为什么调用ReceiveRemoteNotification:fetchCompletionHandler被调用,但通常didReceiveRemoteNotification不是?

时间:2014-02-18 12:47:51

标签: ios objective-c cocoa-touch ios7 apple-push-notifications

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

我还定义了两个委托方法didReceiveRemoteNotification:fetchCompletionHandler和通常didReceiveRemoteNotification

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

如何解决此问题?
为什么我不能有两种委托方法用于后台和普通推送?

1 个答案:

答案 0 :(得分:9)

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

    }

}