application:didReceiveRemoteNotification:fetchCompletionHandler Not Called

后端 未结 8 1342
南方客
南方客 2020-12-01 08:22

It appears the function application:didReceiveRemoteNotification:fetchCompletionHandler is not called when the app has been forcefully quit. It was my impressio

相关标签:
8条回答
  • 2020-12-01 08:23

    The app should be launched even if it is not running. The Apple documentation says:

    When this value is present and a push notification arrives on a device, the system sends the notification to your app (launching it if needed) and gives it a few moments to process > the notification before displaying anything to the user. (iOS App Programming Guide)

    When a push notification arrives, the system displays the notification to the user and launches the app in the background (if needed) so that it can call this method. (UIApplicationDelegate Protocol Reference)

    Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running, the system calls this method regardless of the state of your app. If your app is suspended or not running, the system wakes up or launches your app and puts it into the background running state before calling the method. (UIApplicationDelegate Protocol Reference)

    However when testing with "content-available":1 pushes the app is never launched when it is not running. When the app is suspended it works.

    Did you find yourself a solution Wes?

    0 讨论(0)
  • 2020-12-01 08:24

    When your app has been force-quitted that method is not called. Instead, as usual, (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions is called.

    If the app was opened by tapping "Open" in a notification-popup, the notification is inside launchOptions.

    Get the push-notification dictionary like this:

    NSDictionary * pushNotificationUserInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    
    if (pushNotificationUserInfo)
    {
      // call your handler here
    }
    
    0 讨论(0)
  • 2020-12-01 08:25

    To whom concern in Swift 2.0 I've solved my problem like this is for the background

    if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
    
        pushNotificationAction(remoteNotification as [NSObject : AnyObject])
    }
    
    0 讨论(0)
  • 2020-12-01 08:34

    application:didReceiveRemoteNotification:fetchCompletionHandler: gets called even if the app is suspended, not running at all, backgrounded, or active. Also worth noting that the method is iOS 7 only. Here is the apple documentation.

    HOWEVER if the app was forcibly closed (i.e. by killing with the app switcher), the app will not be launched. (see SO answer) EDIT: I checked this again on iOS 7.1 to see if they fixed this, but it still remains the case that if the app is killed manually, app will NOT be woken up and application:didReceiveRemoteNotification:fetchCompletionHandler: will not be called

    When receiving the push, the app is only woken up only "if needed" to call the application:didReceiveRemoteNotification:fetchCompletionHandler: method (i.e. you have to set the "content-available" flag within the push notification payload. See SO answer). The method will be called again if the user then opens the app by tapping the notification.

    EDIT: haven't checked this on iOS 8. Has anyone else?

    0 讨论(0)
  • 2020-12-01 08:34
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
    *)launchOptions {
    
        //Remote Notification Info
        NSDictionary * remoteNotifiInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
    
        //Accept push notification when app is not open
        if (remoteNotifiInfo) {
           [self application:application didReceiveRemoteNotification: remoteNotifiInfo];
        }
    
        return YES;
    }
    
    0 讨论(0)
  • 2020-12-01 08:37

    I recently met the same problem, and I found Apple updated their documentation and says:

    However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

    application(_:didReceiveRemoteNotification:fetchCompletionHandler:)

    So I guess there's no way to do anything when the app is killed by force quit?

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