【发布时间】:2016-04-27 11:50:00
【问题描述】:
我已经在我的应用中实现了推送通知。
当我的应用程序在前台时,我的应用程序工作正常。
但当应用程序在后台或被杀死时,我的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];
}
与:
- (void) customPushHandler:(NSDictionary *)notification {
// Code to push ViewController
NSLog(@"Push Notification"); //Got it two times when Clicked in notification banner
}
当我的应用程序运行时,ViewController 被推送一次。当我从通知横幅打开我的应用程序时,我的屏幕会被推送两次。
我在customPushHandler 中放置了一个 NSLog,当应用程序处于前台时我得到了一次,当我从通知横幅启动它时得到了两次。
我的代码有什么问题?
【问题讨论】:
标签: ios objective-c iphone push-notification xcode6