ios - 为什么 didReceiveRemoteNotification :fetchCompletionHandler is called but usual didReceiveRemoteNotification isn't?

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

在我的应用程序中,我有两种类型的推送通知:带有 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

    }

}

关于ios - 为什么 didReceiveRemoteNotification :fetchCompletionHandler is called but usual didReceiveRemoteNotification isn't?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21854350/

相关文章:

ios - 错误:“预期返回Int的函数中缺少返回”

objective-c - setImage:不会导致图像更改

objective-c - 使用 ALAssetLibrary 快速知道图像 Assets 是横向还是纵向?

iphone - 如何制作一个采用格式化字符串+几个附加参数的宏,就像 NSLog 一样?

iphone - UITableView 滚动太远并导致奇怪的事情

ios - 涉及多个 View Controller ,如何将值发送回启动 View Controller ?

iphone - 在 UITableView 的完成按钮上隐藏 UIPickerview

iphone - UIView的UIImagePickerController

objective-c - Objective C,实现聊天应用程序的最佳方式(套接字)

iphone - 为什么这个 UIButton 不显示它的文本标签?