According to didReceiveRemoteNotification when in background , we used to be able to handle the user opening the app by clicking the action button on a push notification (or swiping on the push notification, depending on how the user sees push notifications) by implementing -application:didReceiveRemoteNotification:
and then checking inside the method whether the application's applicationState
was not active.
In iOS 7, there's the new remote-notification
background mode, which allows the app to perform background fetch when a remote notification is displayed to the user (without the user necessarily doing anything to the notification). To support this mode, you are supposed to implement the -application:didReceiveRemoteNotification:fetchCompletionHandler:
method.
The documentation for -application:didReceiveRemoteNotification:
says that if your application delegate implements the application:didReceiveRemoteNotification:fetchCompletionHandler:
method, then "the app object calls that method instead of this one." Which means we cannot use -application:didReceiveRemoteNotification:
to handle remote notifications anymore, since it's not going to be called.
We should probably put handling logic in application:didReceiveRemoteNotification:fetchCompletionHandler:
, but the previous trick for handling it doesn't make sense anymore -- previously, we depended on the fact that the only way for -application:didReceiveRemoteNotification:
to be called when the app is not active was if the user tapped the action button on the notification to open the app. However, now, the whole point of the remote-notification
background mode is that it can call application:didReceiveRemoteNotification:fetchCompletionHandler:
in the background every time a remote notification is received, before the user does anything to it.
So then, how can we now tell when the user opens the app using the action button on the notification?
You still check the application state in application:didReceiveRemoteNotification:fetchCompletionHandler:
UIApplicationStateBackground
- App is in the background receiving a push notificationUIApplicationStateInactive
- App is opening from the user tapping a notificationIf 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