我在我的项目中使用 Parse SDK 推送通知。我已经在 didFinishLaunchingWithOptions:
中添加了 parse.com 上给出的代码
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
如果设备或模拟器版本是 iOS 8,它工作正常,但它在 iOS 6.1 中不工作,并出现消息
[UIApplication registerUserNotificationSettings:]: 无法识别的选择器发送到实例 0x208406c0
谁能告诉我怎么解决?
最佳答案
在 didFinishLaunchingWithOptions 方法中使用此代码它在 ios 6 和 7 中有效
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
如果您想在所有情况下都在 ios 6、7、8 中工作,那么请在 didFinishLaunchingWithOptions 中使用此代码
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)];
}
关于ios - RegisterUserNotificationSettings 在 ios 6.1 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27294281/