Reputation: 31303
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?
Upvotes: 6
Views: 1792
Reputation: 21
I was use this delegate function to add the 『Notification Number』.
Cause our Server not send the Badge to our Clients. Then I used the strange method to add the 『Notification Number』 with this delegate function, and I also add a code to switch UIViewController in this function.
I found out when I use the server push Notification to my test App, and the status of test App is in the background, even I am using Twitter or Safari.
My test App also switch UIViewController to another UIViewController after I push Notification from the server.
Upvotes: 0
Reputation: 391
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 notificationUpvotes: 6