gpt4 book ai didi

objective-c - 如何使用 enabledRemoteNotificationTypes 更新代码,因为它是 "not supported in iOS 8"?

转载 作者:太空狗 更新时间:2023-10-30 03:21:09 25 4
gpt4 key购买 nike

这是我用于 RemoteNotificationType 的代码:

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

我得到的错误是这样的:

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

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

最佳答案

您还可以使用此代码:

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
}
}

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

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
}
}

关于objective-c - 如何使用 enabledRemoteNotificationTypes 更新代码,因为它是 "not supported in iOS 8"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26091875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com