tags:

views:

281

answers:

1

Hi,

I was wondering if it is possible for the app on the client to be able to read the data in the payload when an APNS notification is sent?

For example, if the APNS notification said "Hello world!", and the user clicked 'View' to go to the app, would there be a way for the app to see that the APNS notification said "Hello world!".

Thanks.

+2  A: 

APNS notifications are tied to a specific token which is associated with a specific app on a single phone. When the notification arrives, iPhone OS shows the user the alert, plays the sound (if specified), and sets the application badge (if any).

If the app is running and the screen isn't asleep the app is run and the payload JSON packet is handed over. If the app is running and the screen is dark, the user is shown the alert with a single button to unlock the screen then the app is handed the payload. If the app is NOT running the user is given a View/Cancel choice. If they tap View, the app is run and the payload JSON is handed over.

As you can see, in all these cases the JSON packet containing the notification alert, sound, badge, and any other extra bits you send is handed over to the application. The docs show you how to retrieve the JSON packet. It's up to you what to do with it.

If you're thinking of an app seeing the payload headed for another app, then the answer is no. Notifications are tied to specific apps signatures.

Ramin
"If the app is NOT running the user is given a View/Cancel choice. If they tap View, the app is run and the payload JSON is handed over."what if the user cancel and we want to the last badge number as unread on server like mail.
hib
If they hit 'cancel' the app is not notified and the whole payload (including badge number) is discarded. It's under the user's control. Under iOS 4 you can try setting the app to stay alive when in the background and have it periodically ping the server for unread counts. But if the OS needs the memory, your app will get zapped so it's best not to build that expectation in the user. Built-in apps (like Mail) don't play by the same rules.
Ramin