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

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

is different from

application: didReceiveRemoteNotification:
         


        
8条回答
  •  借酒劲吻你
    2021-01-30 17:17

    I'm not sure if I understand your question.

    Do you want to differentiate between a silent push notification background fetch and a noisy push notification? You can simply check whether the push notification dictionary contains the "content-available" key: [[userInfo objectForKey:@"aps"] objectForKey:@"content-available"] If it does, then it should be a silent push. If not, it was a normal push.

    Do you want to know if that background fetch method is called when the application receives a notification and it is in suspended/not running? If so, you can do the following:

    • Download and import LumberJacks into your app. Look through the directions and learn how to set it up such that you can save logs to the disk.
    • Put this in any method you want to see whether/when that method is invoked:

      • DDLogDebug(@"%@ - %@",NSStringFromSelector(_cmd),NSStringFromClass([self class]));

      This will print the class and the method to the log file.

    • Examine the log file after sending yourself a push notification to your background-fetch enabled app, and see if any of the methods get called by looking at your log file.

    If you have set up your app correctly for background fetch, the method application: didReceiveRemoteNotification: fetchCompletionHandler: will be called even when the app is backgrounded/not running if you receive a push notification (silent push or not).

提交回复
热议问题