在 iOS 8.x 下尝试注册推送通知时:
application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)
我收到以下错误:
registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.
任何想法什么是做它的新方法?当我在 iOS 7.x 上运行这个 Swift 应用程序时,它确实有效。
编辑
在 iOS 7.x 上,当我包含我得到的条件代码时(SystemVersion 条件或 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000)
dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
最佳答案
对于 iOS<>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//-- Set Notification
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
//--- your custom code
return YES;
}
适用于 iOS10
关于objective-c - registerForRemoteNotificationTypes : is not supported in iOS 8. 0 及更高版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24454033/