RegisterUserNotificationSettings在ios 6.1中不起作用

时间:2014-12-04 12:36:10

标签: ios objective-c parse-platform ios8

我在我的项目中使用Parse SDK进行推送通知。我在parse.com上给出的didFinishLaunchingWithOptions:中添加了代码

UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];


[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

它工作正常,如果设备或模拟器版本是iOS 8,但它在iOS 6.1中不起作用,并且显示消息

[UIApplication registerUserNotificationSettings:]: unrecognized selector sent to instance 0x208406c0

任何人都可以告诉我如何解决它?

2 个答案:

答案 0 :(得分:29)

在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)];
    }

答案 1 :(得分:1)

对于iOS8:

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}