在 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
https://stackoverflow.com/a/39383027/3560390
关于objective-c - registerForRemoteNotificationTypes : is not supported in iOS 8. 0 及更高版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24454033/
相关文章:
ios - applicationWillEnterForeground 与 application
ios - @property 在 Objective-C 中保留、分配、复制、非原子性
objective-c - 如何测试对象在 Objective-C 中属于哪个类?
iphone - Xcode 4 卡在 "Attaching to (app name)"
objective-c - 在此 block 中强烈捕获 self 可能会导致保留循环
objective-c - 如何检查 NSString 是否以某个字符开头
objective-c - 新的自动引用计数机制是如何工作的?