我需要弄清楚如何在 iOS 8 中关闭徽章、声音和警报
Posted
技术标签:
【中文标题】我需要弄清楚如何在 iOS 8 中关闭徽章、声音和警报【英文标题】:I need to figure out how to turn off badge, sound and alert in iOS 8 【发布时间】:2014-09-18 23:00:30 【问题描述】:我有这段代码可以在 ios7 中运行。它使我能够关闭声音、警报和徽章。如果showMessage,showBadge or show sound
设置为零,则相应的 UIremote 类型也会关闭。众所周知,iOS8 远程通知已经改变。有人可以指导我如何使其适用于 iOS 8 吗?
UIRemoteNotificationType notificationType = UIRemoteNotificationTypeNone;
if (showMessage == 1 )
notificationType |= UIRemoteNotificationTypeAlert;
if (showBadge == 1 )
notificationType |= UIRemoteNotificationTypeBadge;
if (showSound == 1 )
notificationType |= UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationType];
这是我尝试过的,但我收到错误 No visible @interface 'UIApplication' declares selector 'registerForUserNotificationSettings:'
UIUserNotificationType userNotificationType = UIUserNotificationTypeNone;
if (showMessage == 1 )
userNotificationType |= UIUserNotificationTypeAlert;
if (showBadge == 1 )
userNotificationType |= UIUserNotificationTypeBadge;
if (showSound == 1 )
userNotificationType |= UIUserNotificationTypeSound;
[[UIApplication sharedApplication] registerForUserNotificationSettings:userNotificationType];
【问题讨论】:
潜在相关:***.com/a/24488562/1301654 【参考方案1】:在您的代码中,您传递的是 UIUserNotificationType 对象,但您需要传递 UIUserNotificationSettings 对象。
UIUserNotificationType notificarionType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificarionType categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
【讨论】:
以上是关于我需要弄清楚如何在 iOS 8 中关闭徽章、声音和警报的主要内容,如果未能解决你的问题,请参考以下文章