Detect if application: didReceiveRemoteNotification: fetchCompletionHandler: was called by tapping on a notification in Notification Center

前端 未结 8 1803
北荒
北荒 2021-01-30 16:38
application: didReceiveRemoteNotification: fetchCompletionHandler:

is different from

application: didReceiveRemoteNotification:
         


        
相关标签:
8条回答
  • 2021-01-30 17:32

    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)
        }
    }
    
    0 讨论(0)
  • 2021-01-30 17:33

    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:.

    0 讨论(0)
提交回复
热议问题