【发布时间】:2015-04-03 00:59:34
【问题描述】:
我在一个应用程序中使用 UILocalNotification,并且在 iOS 7 或更早版本中运行良好,但在 iOS 8 中根本没有调用 didReceiveLocalNotification。 经过一番研究,我发现在 iOS 8 中我们必须改用 handleActionWithIdentifier,所以我尝试了它,但在 LocalNotification 运行时也没有调用这个 void。 这是我的代码:
我在 didFinishLaunchingWithOptions 中有这段代码,它工作正常,第一次启动应用程序时,我被要求允许提供通知等。
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
然后我得到:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification
completionHandler:(void(^)())completionHandler
{
NSLog(@"handleAction");
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"didReceive");
}
当 localNotification 运行并且我在屏幕上显示的消息上滑动手指时,没有任何反应...根本不会调用日志... 我还注意到,如果应用程序处于活动状态并且正在运行,当 localNotification 运行时,它会被调用方法 didReceiveLocalNotification 有人知道我在做什么错吗?感谢您的帮助
【问题讨论】:
标签: ios iphone ios8 uilocalnotification