swift 和 iOS 7.1 的远程通知错误
Error on remote notifications with swift and iOS 7.1
我在 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 工作正常。你能指出我如何解决它吗?
UIUserNotificationSettings
可从 ios 8 连同 registerUserNotificationSettings
您可以将 registerForRemoteNotificationTypes
用于 iOS 7,但您需要在运行时(OS 版本)检测它并使用正确的方法。
我在objective-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)];
}
我在 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 工作正常。你能指出我如何解决它吗?
UIUserNotificationSettings
可从 ios 8 连同 registerUserNotificationSettings
您可以将 registerForRemoteNotificationTypes
用于 iOS 7,但您需要在运行时(OS 版本)检测它并使用正确的方法。
我在objective-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)];
}