我在我的應用程序中實現了推送通知。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 –