Push notifications are useful for keeping users informed with timely and relevant contents. Push notifications can be sent regardless whether the app is running, inactive or in the background. Notifications can display an alert; play a distinctive sound or update badge on your app icon.
In this post, I will walk through the process of enabling push notification for an app in Apple developer portal, upload the generated certificate to Everlive and finally register my device in Everlive to receive push notifications.
Before you begin, note that you cannot test push notifications in iOS simulator. You need an iOS device as well as an Apple developer account. You also need to sign up for Everlive in order to send push notifications using its service.
At this point you will be creating the SSL certificate that is to be associated with the IOS app in Apple developer portal.
You will first launch the Keychain Access application in your mac. Next go to Menu-> Keychain Access -> Certificate Assistant - > Request a Certificate From a Certificate Authority
This will bring up the following wizard:
Here you will select “Saved to disk” option and once completed it will prompt you to save the .certSigningRequest file in your mac.
In this step you will create the App ID in Apple Developer portal. App ID is basically the unique identifier of the iOS app generally represented by a reversed address (ex. com.telerik.EverliveApp). Here to note that this identifier should not contain any wildcard (*) characters.
Steps for creating an App ID are listed below:
Configuring the App ID includes creating the development certificate to receive push notifications.
Once the App ID is created and configured, the next step is to create a provisioning profile based on it in order to deploy the app in a device.
Steps for configuring a provisioning profile are:Go to “Certificates, Identities and Profiles” from “Apple Developer Member Center”.
Now the .p12 file that is created in previous step should be uploaded to Everlive portal. This will be used by Everlive to send notifications to a registered device through Apple Push Notification Service (APNS).
In order to do so select the app which you want to configure. Go to Settings-> Push Notifications and upload your .p12 file under iOS-> Development.
In order to receive notifications in an iOS device, you have to call [application registerForRemoteNotificationTypes:] method in appDelegate’s [application didFinishedLaunchingWithOptions:] method. This will prompt the user (first time the application is run) if he wants to allow push notifications for the app and once he confirms,
the following method will be called:
Here I am storing the device token in client library singleton that will be used later to register the device in Everlive.
As the registerForRemoteNotificationTypes is called, it will validate the App ID and profile that is used to deploy the app. In case of any errors, it will call the following method in app delegate:
Device is registered in Everlive by calling the following method from the SDK:
If everything went right, sending a notification from Everlive cloud will call the following method in app delegate:
When a push notification is received while the app is not in foreground, it is handled by iOS notification center. However, when the app is active it is developer’s job to handle the notification in the method mentioned above. Here, I just called the [Everlive handlePush:userInfo] method that creates an UIAlertView dialog to show the notification.
It is also possible to unregister a device from Everlive. You can do this in the following way:
Here to note that [Everlive sharedInstance] contains your default API key that you initialized either in [application didFinishedLaunchingWithOptions:] or info.plist file. Please refer to the getting started with Everlive iOS SDK section for more.
In addition, it is also possible to set custom parameters while registering the device. This will be useful in filtering a range of devices for sending push notifications.
Parameters can be set in the following way:
Before you deploy the app in a device and start receiving push notifications. You have to the set the provisioning profile containing the App ID created previously in Build Settings -> Code Signing -> Provisioning Profile property.
Once done, you can send notifications to your device using the following command:
However, it is also possible to send notifications from Everlive admin portal. Navigate to App -> Push Notifications -> Add New Push Notification where you can further filter devices based on custom parameters:
In this post I have created a provisioning profile from an App ID with push notification enabled. I then walked through the process of registering the device in Everlive and sent a notification using curl. Everlive and equivalent providers simplify the process of sending push notifications to your device. Apple Push Notification service transports and routes a notification from a given provider to a given device.
It is possible to write your own provider, however in that case you have to manually configure the payload dictionary, validate device and deal with security. Moreover, each platform handles push notifications differently like Android uses Google cloud. In that case, you have to manually implement providers for each platform. Everlive on the other hand will take care of the platform specific details and relay your notifications to all associated devices without requiring you to go under the hood.
Finally, I have skipped the configuration of Everlive SDK in Xcode, which is beyond the scope of this article. Please refer to the original SDK documentation @http://docs.everlive.com to dig further.
Subscribe to be the first to get our expert-written articles and tutorials for developers!