didReceiveRemoteNotification

didReceiveRemoteNotification

在我的应用程序中,我有两种类型的推送通知:带content-available = 1标志的远程静默通知和带有bodybadge和其他内容的常规推送通知。

我还定义了两个委托(delegate)方法didReceiveRemoteNotification:fetchCompletionHandler和常规的didReceiveRemoteNotification

但是,当没有content-available标志的推送通知到达时,将调用didReceiveRemoteNotification:fetchCompletionHandler而不是didReceiveRemoteNotification

如何解决这个问题?
为什么不能为后台推送和常规推送使用两种委托(delegate)方法?

最佳答案

iOS 7仅调用了新版本,这就是我在应用程序中的处理方式:

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    // Pass on
    [self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:nil];

}

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    // Check if in background
    if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) {

        // User opened the push notification

    } else {

        // User hasn't opened it, this was a silent update

    }

}

10-08 06:23