我在我的应用程序中实现了推送通知。didReceiveRemoteNotification调用了两次
当我的应用程序是在前台,然后我的应用程序工作正常。
但是,当应用程序在后台或被杀然后我didReceiveRemoteNotification
调用两次。
我已经处理推送通知,并要求从didFinishLaunchingWithOptions
这种方法和didReceiveRemoteNotification
这里的常用方法是我实现:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *pushDictionary = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (pushDictionary) {
[self customPushHandler:pushDictionary];
}
return YES;
}
和:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
[self customPushHandler:userInfo];
}
AND:
- (void) customPushHandler:(NSDictionary *)notification {
// Code to push ViewController
NSLog(@"Push Notification"); //Got it two times when Clicked in notification banner
}
当我的应用程序运行时,ViewController被推送一次。当我打开我的应用程序从通知栏,然后我的屏幕被推两次。
我放在的NSLog在customPushHandler
,我得到了它,当应用程序在前台和两个时间,当我从通知横幅启动它一次。
有什么问题在我的代码?
参考http://stackoverflow.com/questions/22085234/didreceiveremotenotification-fetchcompletionhandler-open-from-icon-vs-push-not#comment51407901_22085855 –