在我的应用程序中,我有两种类型的推送通知:带有 content-available = 1
标志的远程静默通知和带有 body
、badge< 的普通推送通知
和其他东西。
我还定义了两个委托(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/