关于iphone:您可以从App端静音传入的推送通知[iOS]

Can you mute incoming Push Notifications from the App side [iOS]

我正在制作一个使用Apple Push Notifications的应用程序。我希望能够有一个"下班"模式,在该模式下仍会接收到推送通知,但传入时没有声音播放。是否可以从应用程序内部使这些推送通知静音?我知道我无法从JSON消息中发送声音,但是如果我可以从应用程序内部进行操作,则会更容易。我仍想接收通知,所以我不想从推送通知中注销


如果您的应用程序处于后台,则静音推送的唯一方法是不发送JSON消息中的声音。

当您的应用程序处于前台状态时,您将收到以下应用程序推送:didReceiveRemoteNotification:在这种情况下,无论您是否发送声音,应用程序都会静默接收推送。


您可以将注册更改为不包括声音。

当您想发出通知时,请致电:

1
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

当您想要使通知静音时:

1
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];

这将仅显示警报和徽章。声音将不会播放。

编辑:

我相信以下引号表示如果有效负载包含未启用的类型,则不会过滤该通知。设备只会显示/显示未启用的类型。

The system does not badge icons, display alert messages, or play alert sounds if any of these notifications types are not enabled for your app, even if they are specified in the notification payload.

您还应该注意,无论您的应用选择启用还是禁用通知类型,用户都可以手动覆盖该决定:

Users can modify the enabled notification types at any point, using Settings in iOS or System Preferences in OS X.