1

Below is my request notification code

if #available(iOS 10, *) {
        UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
        application.registerForRemoteNotifications()
    }

I have asked for sound, alert, and badge permissions from user in notification. I also went through the link below regarding the push notification vibration.

vibrate in push notification

My question is push notification vibration when the app is closed is handled by app or it's the payload which makes iPhone vibrate.

Is it possible to handle vibration of iPhone from push notification, like sound key in payload of push notification or is there any other way to control push vibration?

Thanks in advance

Yash Tamakuwala
  • 1,789
  • 1
  • 24
  • 33

2 Answers2

1

You can actually control the vibration within the payload by specifying the sound. If you are specifying your own sound, there might be not vibration but if you just take the default sound, the device will vibrate!

Example payload:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff" // or set this to the default sound
    }
}
Laurens
  • 48
  • 8
1

You can't.

To trigger a vibration on the phone you need:

  • In your payload you need sound field under aps key
  • The device needs to have vibration enabled.

Obviously you can't control the vibration of a phone from the payload

mfaani
  • 33,269
  • 19
  • 164
  • 293
  • {"aps":{ "alert":"rich notification", "mutable-content":1, "badge":1, "sound": "default" }, "mediaUrl":"https://www.simform.com/static/adopting-process-men.png", } This is ny payload still my phone is not vibrating – Jasmine Chaniara May 09 '20 at 17:20
  • See sample payload from [here](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification). The “sound” must be a field of the “aps” key. Your have yours under the “alert” key. It’s also better if you include that payload in your question. – mfaani May 09 '20 at 17:53