在我的应用程序中,我有两种类型的推送通知:带有content-available = 1
标记的远程静默通知和带有body
,badge
和其他内容的常规推送通知。
我还定义了两个委托方法didReceiveRemoteNotification:fetchCompletionHandler
和通常didReceiveRemoteNotification
。
但是,当没有content-available
标志的推送通知到达didReceiveRemoteNotification:fetchCompletionHandler
时,而不是didReceiveRemoteNotification
。
如何解决此问题?
为什么我不能有两种委托方法用于后台和普通推送?
答案 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
}
}