Search code examples
iosswiftaudiovibrationremote-notifications

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


I have settings in my app, in that I have a toggle button for turning On and Off the sound and vibration as well, while receiving remote notification. Below is my code for registering remote notification in AppDelegate

let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Sound]
    let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    application.registerUserNotificationSettings(pushNotificationSettings)
    application.registerForRemoteNotifications()

For sound I referred this Remove sound from notification but it does'nt seems to work.

Whatsapp having this feature, so surely it will be possibly

Can anyone please advise in this?


Solution

  • please remove sound key-value from JSON payload.

    I have just checked it. It works for me.

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