When user taps on a remote notification, the following callback is triggered in the app delegate:
-application:didReceiveRemoteNotification:fetchCompletionHandler:
in this scenario, application is launched and the app state is UIApplicationStateActive
which I interpret it as user actioned on a remote notification.
the problem: This method can also get called when a remote notification arrives and app is in the foreground with inactive state.
example: when notification center view is open(swipe from top edge of screen down) or a UIAlert is open. In both case application state is UIApplicationStateActive
and there is no way to tell whether it's a user actioned notification or system push received.
Q: How can I determine if didReceiveRemoteNotification
callback is response to user tapping on remote notification vs arrival of remote notification?
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
//When your app is in foreground and it received a push notification
}
else if (state == UIApplicationStateInactive)
{
//When your app was in background and it received a push notification
}
Also, didFinishLaunchingWithOptions will be called if the app was not running and the user tapped a notification. I have not tried it but i can assume you can get the notification details from options.
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