Oct 26, 2009
First Look at Apple Push Notification Service
I’ve been looking at several ideas that would be would be needing Apple Push Notification service (APNs). This is going to be my quick research to summarize the state of APNs for current / future projects by Apptivity Lab.
APNs runs on iPhone OS 3.0 to handle:
- “Pushing” text, sound and badges to an installed application without requiring any action from the user.
- Even while the application is not currently running on the iPhone OS device.
- An application’s “background processes” to be run — on a server, not the device.
Apple has a one-page overview of the feature.
User perspective
An application can receive text notifications that show as an alert; sound notifications that are played; or a badge notification that adds a number badge to the app icon (like unread emails for Mail). If the application is already running, it may choose to handle the notifications differently.
User’s can change each push-enabled application’s settings by going to Settings > Notifications. For each push-enable application, user can select whether or not to enable Sounds, Alerts, and/or Badges. There’s also a setting turn off notifications for all applications.
A device will only receive notifications for/form applications that are installed and have been run at least once on the device.
Developer Perspective
Think of it as a client-server model. Developer deploys the client as an application on the user’s device. The server uses APNs to push notifications to the device, even if the application is not currently running on the device.
In actual implementation, the server only sends notifications thru the APNs to the device. There isn’t a direct path from the provider to the device, and it is sent asynchronously. Should the device be offline at the time notification is sent, APNs stores the notification for later delivery. Only 1 notification will be stored per application.
The basic security model is: an application registers itself with APNs on its first launch. The device-application pair is given a “device token” by APNs. The application is expected to send the device token to the provider’s server. With that device token, the provider can communicate with the device thru APNs.
The actual message sent from provider is a JSON object. It can hold a text message to be alerted, a number to display as a badge on the application icon, or a sound name (referencing a system sound or a sound file in the application bundle) to be played. Combinations of the above is possible too.
Apple provides a separate Sandbox and Production APNs. To use them, developers need a SSL cert (available at the iPhone Developer’s Portal). The SSL cert is to be install on the provider’s server.
Requirements
- iPhone OS 3.0 or later
- Internet connection (wifi, 3G, etc) that allows communication over port 5223
- Wifi will only be used if there is no cellular data connection
- While on wifi, device will only receive notifications if the device is plugged in or if the device display is on.
My Questions
- Can I push sounds dynamically to the device?
No. “Pushing” a sound is actually pushing the filename of a sound file within your application bundle. Scrap the thought of pushing…. voice mails (example). Fart-Push however, will work. I dread the day Fart apps get Push functions. - How reliable is Push Notifications — rather, under what conditions will APNs not be able to push?
- If I remove an application, will I still receive push notifications for that app?
No. The device will refuse the notification if the target application has been uninstalled. APNs has a feedback service to inform the providers which devices are refusing the notifications, so that it can stop sending to that device. - How long does APNs store notifications for offline devices?
Not sure at this point.
References
developers.apple.com: Apple Push Notification Service Programming Guide
mobileorchard.com: The Hidden Costs of Apple’s Push Notification Service
arstechnica.com: The problem with push: can small developers afford it?
highscalability.com: Apple’s iPhone to use a centralized push based notification architecture
Sounds cool! =)