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