我在我的项目中使用Parse SDK推送通知.我已经在doFinishLaunchingWithOptions中添加了代码:在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
任何人可以告诉我如何解决?
解决方法
在doFinishLaunchingWithOptions方法中使用此代码,它在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)];
}