application: didReceiveRemoteNotification: fetchCompletionHandler:
is different from
application: didReceiveRemoteNotification:
In case of swift
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let state : UIApplicationState = application.applicationState
if (state == .Inactive || state == .Background) {
// go to screen relevant to Notification content
} else {
// App is in UIApplicationStateActive (running in foreground)
}
}
You could check the UIApplication
's applicationState
to distinguish silent calls from calls made with the application being actively used by the user:
typedef enum : NSInteger {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} UIApplicationState;
Or keep your own flag set on the delegate
's applicationDidEnterBackground:
.