如何使用 enabledRemoteNotificationTypes 更新代码,因为它“在 iOS 8 中不受支持"? [英] How to update code using enabledRemoteNotificationTypes because it is "not supported in iOS 8"?

查看:16
本文介绍了如何使用 enabledRemoteNotificationTypes 更新代码,因为它“在 iOS 8 中不受支持"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用于 RemoteNotificationType 的代码:

this is the code i used for the RemoteNotificationType:

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

我得到的错误是这样的:

The error i got was this:

2014-09-29 15:46:47.416 Dummy[258:21766] enabledRemoteNotificationTypes 在 iOS 8.0 及更高版本中不受支持.

2014-09-29 15:46:47.416 Dummy[258:21766] enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.

如果有人能给我解决方案,那将是一个很大的帮助.

Would be a great help if someone could give me the solution.

推荐答案

您也可以使用此代码:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {

    UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];

    if (types == UIUserNotificationTypeNone) {
        // Do something
    }

} else {

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    if (types == UIRemoteNotificationTypeNone) {
        // Do something
    }
}

或者如果您只想检查用户是否注册了远程通知,则使用此方法:

Or this one if you only want to check the user is registered for remote notifications:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {

    BOOL isRegisteredForRemoteNotifications = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

    if (isRegisteredForRemoteNotifications) { 
        // Do something
    }

} else {

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    if (types == UIRemoteNotificationTypeNone) {
        // Do something
    }
}

这篇关于如何使用 enabledRemoteNotificationTypes 更新代码,因为它“在 iOS 8 中不受支持"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆