Posted by Dhepthi L Narasimhan on March 21st, 2012
Push Notification is one of the challenging concept in all smart phones. Especially when it comes to Iphone push, it is quite long process. I recently had a chance to try Push notification in Iphone.
The most difficult task is to create SSL certificate and Provisional certificate. Let’s see how to create it and make use of it.
1. Create Certificate Signing Request (CSR)
* Request a Certificate from authority as shown
* It will open a dialog, follow the process to create the certificate. The certificate with certSigningRequest extension will be created.
Save the certificate to disk for further use
2. Create SSL Certificate
* Create a New App ID by clicking on APP IDs in the left menu as shown
* To enable Push Notification, check the Enable Push Notification Service box and clicking Configure button will open an dialog box as shown
* The Dialog will prompt for CSR certificate. Upload the certificate just created in above steps and follow the window to create APN certificate
* Opening it in Keychain Access, you will able to see Certificate, Private,Public Key as shown
3. Create Provisioning Profile
* Create Provisioning profile by clicking Provisioning in left menu of IOS provisioning portal as shown
* By filling the necessary details, Development Provisioning profile with mobileprovision will be generated as shown
* Download,open it in Xcode and install the profile for your iphone/ipad.
4. Export APN certificate to .pem format
* Open KeyAccess, Select your generated certificate alone with private key and export it to p12 format as shown
* In terminal, use the following code to export it to pem format
openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes
Make a note .pem certificate file, we will use it in ruby
5. Device Token
* Create a rhodes app
rhodes app app_name
* Enable push in build.yml
capablities: - push
* In terminal, type the following to run your rhodes app in Iphone through Xcode
rake swtich_app rake build:iphone:setup_xcode_project
* Connect you device to Mac. Open rrhorunner.xcodeproj in Xcode and run the rhodes app in your device.
* Running you app in device will prompt you to allow for notification as follows
* Clicking Allow will get the device id from device. You can get the device id from the log window of xcode or through code as
System.get('device_id') # => D12f5sad7673-h543
6. Send Messages using ruby gem
* First install apns gem as
gem install apns
* Configure apns with your generated pem file, device token as
APNS.host = 'gateway.sandbox.push.apple.com' APNS.pem = '/path/to/your/cert.pem' APNS.port = 2195 device_token = 'your_device_token'
* Send notification to your ios device as
APNS.send_notification(device_token, 'Hello iPhone!')
The entire code looks like
require 'apns' APNS.host = 'gateway.sandbox.push.apple.com' APNS.pem = '/path/to/your/cert.pem' APNS.port = 2195 device_token = 'your_device_token' APNS.send_notification(device_token, 'Hello iPhone!')
Note : Mobile Provision will not be installed in your xcode until it has the proper private key associated with it.
We will get an message in IOS device. I hope this blog would be useful to send push notification in Iphone using ruby gem. Any suggestion or comments are most welcomeTags: apple, iPhone, Push, rhodes, rhomobile, Ruby
Unique Views: 2230 Total views: 2810
Follow responses at RSS 2.0. Leave a response | Trackback.
2 Responses to “IPhone Push Notification using Ruby”
Leave a Reply