Hello There, I got a problem in which I have to send the push notification on iphones when some event occurs by the rails application. For this I have used rubygem 'grocer'. Here is the sample implementation for this:
1. Introduction:
APNS(Apple Push Notification Service) The Apple Push Notification Service (APNs) is a service created by Apple Inc. that forwards notifications of third party applications to the Apple devices; such notifications may include badges, sounds or custom text alerts. It was launched together with iOS 3.0 on June 17, 2009.[1] In iOS 5's Notification Center added pushing local notifications. APNs was also added as an API to Mac OS X v10.7 "Lion" for developers to take advantage of,[2] and was improved in OS X 10.8 "Mountain Lion" with the introduction of Notification Center.
2. Install Gem:
Follow these steps:
1. install Gem by using `gem install grocer`. or write `gem 'grocer'` in side your Gemfile and run
'bundle install'.
3. Sending notifications:
a. Create a pusher object to send notifications:
@pusher ||= Grocer.pusher( certificate: _pem_file, passphrase: passphrase, gateway: gateway, port: port, retries: retries )
where _pem_file => is the location of your certificate.pem file.
passphrase => is the passphrase while creating the pem file.gateway =>1.For development and staging: 'gateway.sandbox.push.apple.com'2. For production : 'gateway.push.apple.com'port => 2195retries => is maximum number of retries.b. Create notification object:notification = Grocer::Notification.new( device_token: YOUR_DEVICE_TOKEN, alert: YOUR_MESSAGE, badge: 42, sound: 'siren.aiff')where device_token is the device token on which you want to send the notification.c. Send Notifications:@pusher.push(notification)this will send a notification on your given device.Thanks for reading this blog.