In my application I have two types of push notifications: remote silent notifications with content-available = 1
flag and usual push notifications with body
, badge
and other stuff.
在我的应用程序中,我有两种类型的推送通知:带有content-available = 1标志的远程静默通知和带有正文,徽章和其他内容的常规推送通知。
I also define two delegate methods didReceiveRemoteNotification:fetchCompletionHandler
and usual didReceiveRemoteNotification
.
我还定义了两个委托方法didReceiveRemoteNotification:fetchCompletionHandler和通常的didReceiveRemoteNotification。
But when a push-notification without content-available
flag arrives didReceiveRemoteNotification:fetchCompletionHandler
is called, instead of didReceiveRemoteNotification
.
但是当没有content-available标志的push-notification到达时,会调用didReceiveRemoteNotification:fetchCompletionHandler,而不是didReceiveRemoteNotification。
How to fix this?
Why can't I have two delegate methods for background and usual pushes?
如何解决这个问题?为什么我不能有两种委托方法用于后台和常规推送?
1 个解决方案
#1
9
iOS 7 only calls the new one, this is how I handled it in my app:
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
}
}
#1
9
iOS 7 only calls the new one, this is how I handled it in my app:
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
}
}