接收远程通知时开启on/off振动和声音iosswift

Turn on/off vibration and sound while receiving remote notification ios swift

我的应用程序中有设置,因为我有一个切换按钮,用于打开 OnOff soundvibration,同时接收远程通知。下面是我在 AppDelegate

中注册远程通知的代码
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Sound]
    let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    application.registerUserNotificationSettings(pushNotificationSettings)
    application.registerForRemoteNotifications()

对于声音,我提到了这个 Remove sound from notification 但它似乎不起作用。

Whatsapp有这个功能,所以肯定有可能

谁能在这方面提供建议?

请从 JSON 有效负载中删除声音键值。

我刚查过。对我有用。

{"aps":{"alert":"Enter your message","badge":1}}