Skip to content

Push notifications tutorial

Simbul edited this page Mar 25, 2013 · 10 revisions

This will only be a tutorial on implementing Push Notifications in Baker. For general information about Push Notifications, see:

APNS device token

You will need an APNS device token for any device you want to send a notification to. The token is generated on the device when a user agrees to receiving push notifications when first opening an app. Baker will send the token to your server using the APNS device token endpoint.

Push notification for the latest issue

Baker applications natively support only Newsstand Content Availability notifications, the ones used to start the background download of a issue. The standard payload that you must send within your notification is a JSON object exactly like this:

{
    "aps": {
        "content-available": 1
    }
}

This will cause a refresh of the shelf and the background download of the latest issue.

Push notification for a specific issue

Baker applications also support the background download of a specific issue on the shelf. To specify which issue is the one that should be downloaded you could extend the notification payload like this:

{
    "aps": {
        "content-available": 1
    },
    "content-name": "a-study-in-scarlet"
}

This will cause a refresh of the shelf and the background download of the issue named "a-study-in-scarlet"

Known pitfalls

There are two things to remember while working with push notifications in Baker (or in any other application), which are already pointed out in the links posted above, but deserve a direct reminder here:

  • You can start only one background download every 24 hours. However, you can override this limit while testing, by enabling NKDontThrottleNewsstandContentNotifications in AppDelegate.m, as in the following example:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NKDontThrottleNewsstandContentNotifications"];
    ...
  • While you can extend the support to the other types of notification and/or customize your notification payload with other custom properties, you should keep the "aps" object reserved for Apple coded properties and add custom properties outside it.