Reputation: 1922
I need to handle remote push notifications based on when I get them. When the app is in the background or terminated and if I get a push notification, and when I tap the push notification, I handle that in `
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
where I can tell the visible UIViewController
to push to the necessary view.
However, when I receive a remote push notification while I'm already inside the app, I don't want the app to do anything but increment the notifications counter on the home view. Right now it does the same thing, which pushes to the necessary view, but this should only be happening when the app was at first in the background and the user tapped the push notification to enter the app.
How do I differentiate between these two use cases?
Upvotes: 0
Views: 653
Reputation: 6620
You can check the "applicationState" property of UIApplication class.
UIApplicationState applicationState = [UIApplication sharedApplication].applicationState;
if(applicationState==UIApplicationStateActive){
NSLog(@"push message received when app was active"):
}else{
}
You can do this check in the below delegate method which you already use.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Hope it helps!!
Upvotes: 3