Getting Pushy…

A few months ago, we built an iOS App for Dead Man’s Snitch. The drive behind making it a native application was to take advantage of the Apple Push Notification System. When the App went live to our customers via the App Store it quickly became clear that we were missing notifications sent from Dead Man’s Snitch.

We had notifications working fine, but when you have the app open, it doesn’t show the native notification widget you expect, so it looked like they weren’t working. The app still gets the notification, so we just had to do something with it.

iOS relies on the user to handle a push notification when it is received while the app is running. In order to do so, we implement the didReceiveRemoteNotification: method in the application delegate.

The OS calls didReceiveRemoteNotification: and sends the push notifications information along in the userInfo dictionary under the “aps” key.

For us, the fix was straight forward:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSLog("APN Received: %@", userInfo[@"aps"][@"alert"]);
    [[NSNotificationCenter defaultCenter] postNotificationName:@"DMSPushNotificationReceived" object:nil userInfo:nil];
}

When the table view receives DMSPushNotificationReceived, we refresh all of the users snitches from the server. No more lost push notifications! :)

tim@collectiveidea.com

Comments