首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RegisterUserNotificationSettings不在IOS6.1中工作

RegisterUserNotificationSettings不在IOS6.1中工作
EN

Stack Overflow用户
提问于 2014-12-04 12:36:09
回答 2查看 6.6K关注 0票数 9

在我的项目中,我使用Parse进行推送通知。我在didFinishLaunchingWithOptions:中添加了parse.com提供的代码

代码语言:javascript
复制
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

有人能告诉我怎么解决吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-04 12:47:39

在didFinishLaunchingWithOptions方法中使用此代码它是在ios 6和7中工作的

代码语言:javascript
复制
[application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];

如果您想在所有情况下都在ios 6、7、8中工作,那么在didFinishLaunchingWithOptions中使用以下代码

代码语言:javascript
复制
 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)];
    }
票数 29
EN

Stack Overflow用户

发布于 2015-07-24 13:13:01

对于iOS8:

代码语言:javascript
复制
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)];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27294281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档