views:

586

answers:

1

Hello,

I was just wondering if there was anyway my iPhone application could get the content of the last push notification which was sent to it?

Basically I want to perform specific actions; based on the notification type received.

Kind Regards Mick

A: 

In the push notification, you can send a "payload" which gets transferred to your app on open:

Your application shall get the "userInfo" (NSDictionary) as a param to didFinishLaunchingWithOptions() method.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Parameters
application
The application interested in the remote notification.
userInfo
A dictionary that contains information related to the remote notification, potentially including a badge number for the application icon, an alert sound, an alert message to display to the user, a notification identifier, and custom data. The provider originates it as a JSON-defined dictionary that iPhone OS converts to anNSDictionary object; the dictionary may contain only property-list objects plus NSNull.

To set the payload, see the Apple Push Notification Service Programming Guide. Basically, you can send any kind of info in there to help the app route the user to the correct spot internally.

coneybeare
Remember, this is ONLY if the user allowed the app to open when they received the "push" notification. If the user did not allow the app to open, the information will not be received by the app on subsequent open(s) of the app. The app will have to query the sending server for updates that it should've received when closed.
Jann