[英]Error on remote notifications with swift and iOS 7.1
我在var setting...
上遇到以下错误var setting...
仅在iOS 7.1上显示以下行:
没有更多的线索了。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound;
var setting = UIUserNotificationSettings(forTypes: type, categories: nil);
UIApplication.sharedApplication().registerUserNotificationSettings(setting);
UIApplication.sharedApplication().registerForRemoteNotifications();
return true
}
在iOS 8.1和8.2上运行良好。 您能指出我该如何解决吗?
我在目标C中实现了以下目标,可能会对您有所帮助。
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]){
// This will execute for iOS 8
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else {
// This will execute for iOS 7 and prior
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
UIUserNotificationSettings
可从ios 8与registerUserNotificationSettings
一起使用
您可以使用iOS 7的registerForRemoteNotificationTypes
,但需要在运行时(操作系统版本)进行检测,并使用正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.