【问题标题】:How to turn off specific notification types on iOS如何在 iOS 上关闭特定的通知类型
【发布时间】:2015-01-30 01:53:55
【问题描述】:

在我的应用的第一个版本中,我注册了它:

(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge).

我就是这样做的:

UIUserNotificationType userNotificationTypes = (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                                 categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

现在在我的应用程序的第二个版本中,我决定通过再次注册通知来放弃徽章通知:

UIUserNotificationType userNotificationTypes = (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                                 categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

我原以为从现在开始会关闭徽章通知。当我进入设置菜单并检查我的应用程序的通知设置时。徽章的切换开关不见了,但徽章编号仍在更新。

我怀疑我的方法只是未注册 UIRemoteNotificationTypeBadge,但没有将其关闭。有没有办法做到这一点?谢谢!

【问题讨论】:

    标签: ios cocoa-touch apple-push-notifications


    【解决方案1】:

    我不确定为什么没有关闭徽章通知,但如果您决定放弃徽章通知,您可以在服务器端禁用它们。只需不要在您发送的推送通知的 JSON 有效负载中发送徽章编号。

    即使您设法在客户端禁用标记通知,您仍然应该在服务器端禁用它,以免在计算和发送客户端不会使用的数据时浪费 CPU 和带宽。

    【讨论】:

    • 谢谢。那将是我最后的手段,但我仍然很好奇是否有办法将其关闭。
    猜你喜欢
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多