微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

RegisterUserNotificationSettings在ios 6.1中不起作用

我在我的项目中使用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)];
    }

原文地址:https://www.jb51.cc/iOS/329869.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐