I've read a number of questions here on SO regarding receiving push notifications while the application is not running (more than in the background, meaning it is shut down completely). This question in particular is most helpful in figuring out how to determine if one was receiving using the launchOptions dictionary.
However, I'm very confused, and I fully admit this may be a massive oversight on my part: when my device receives a push notification for this application while the app is shut down, and I later open my application, the launchOptions dictionary is a null pointer. From the description of the accepted answer in the previously mentioned link, and other places too, I gather that I should be able to see a notification payload; however there is nothing. I am developing for iOS 5.1.1.
My only other thought is to check the number of badges on start up (greater than zero, do something...), but this seems very unreliable.
Can anyone tell me what I am missing? Thank you in advance for your help!
application:didFinishLaunchingWithOptions:
will only be called with payload information when app is launched due to notification. E.g. this could happen if user taps over notification alert (added in notification center) or notification received with content-avialble = 1
in payload (Newsstand notification) & provided your app is not in foreground as well in background.
If your app receives notification when app is in background. If it is Newsstand notification or if user taps over action button of alert below method is called
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
with [[UIApplication sharedApplication] applicationState]
not equal to UIApplicationStateActive
.
In above case if user does not tap over action button of notification alert and launch app by tapping over it, neither didFinishLaunchingWithOptions
or didReceiveRemoteNotification
is called.
If your app receives notification while in foreground didReceiveRemoteNotification
is called [[UIApplication sharedApplication] applicationState]
will be equal to UIApplicationStateActive
.
For badge in notification
, if your app is not running no code is executed and the badge is incremented by 1 in app icon. When you launch app (tap on app icon) didFinishLaunchingWithOptions
is called with normally. (If app is in background or foreground when notification received, same as above)
So I think this covers every possible case. Also note that the background case is valid for iOS SDK >= 4.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With