edz*_*o27 5 ios uilocalnotification ios8
是否存在任何已知问题:
application:didReceiveLocalNotification delegate
Run Code Online (Sandbox Code Playgroud)
在iOS 8上?
我的应用程序创建使用本地通知UILocalNotification.当应用程序在后台时我收到通知,当我点击通知横幅时,它会移动到我的应用程序.但这种方法:
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Run Code Online (Sandbox Code Playgroud)
从未在iOS 8(Xcode 5.1.1)上调用,但在iOS 7或更早版本上运行良好.
PS我还测试了这个站点的项目:http: //www.appcoda.com/ios-programming-local-notification-tutorial/ ,它在iOS 8上不起作用.
实际上,iOS 8上的解决方案是向用户请求对通知设置的授权,否则将永远不会调用委托方法-didReceiveLocalNotification :. 您可以通过将此代码添加到-didFinishLaunchingWithOptions:方法来执行此操作:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
categories:nil]];
}
Run Code Online (Sandbox Code Playgroud)
这将向用户显示一个警报视图,要求显示通知的权限.如果她接受,则只要触发本地通知,就会调用委托方法.
用于iOS8
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler{
}
Run Code Online (Sandbox Code Playgroud)