Reputation: 37581
I need to determine if my app is receiving a push directly (when it is in the foreground) versus when the user has tapped on a push which is in the notification center thus invoking my app.
The problem is that in both cases didReceiveRemoteNotification:fetchCompletionHandler: is invoked. So when this method is invoked how can the app tell under which circumstance it was invoked?
Upvotes: 0
Views: 49
Reputation: 11928
I currently implement this in didReceiveRemoteNotification. Hope it is pretty self explanatory!
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if ( application.applicationState == UIApplicationStateBackground )
{
//opened from a push notification when the app was on background
}
else if ( application.applicationState == UIApplicationStateInactive )
{
//push was received while inactive
}
else if ( application.applicationState == UIApplicationStateActive )
{
//push was received while in the foreground
}
}
Use states as necessary. From the Docs
UIApplicationStateActive
The app is running in the foreground and currently receiving events.
UIApplicationStateInactive
The app is running in the foreground but is not receiving events. This might happen as a result of an interruption or because the app is transitioning to or from the background.
UIApplicationStateBackground
The app is running in the background.
Upvotes: 1