繁体   English   中英

如何在iOS上关闭特定的通知类型

[英]How to turn off specific notification types on iOS

在我的应用程序的第一个版本中,我在以下位置进行了注册:

(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,但未将其关闭。 有没有办法做到这一点? 谢谢!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM