我需要弄清楚如何在 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 中关闭徽章、声音和警报的主要内容,如果未能解决你的问题,请参考以下文章

如何在WPF中关闭Tab关闭按钮?

iOS 推送通知 - 如何在没有声音的情况下指定警报和徽章?

在 WPF Frame 控件中关闭导航页面声音

我是不是需要在 Java 中关闭 IO 流? [复制]

如何在自定义 iOS 应用扩展中关闭横向?

如何使用 Cordova 6 在 iOS 中关闭“需要全屏”选项?