0

Is there a way to disable the vibration via push notification payload when notification displayed?

This is my sample payload.

$payload = array
        (
            'title'         => 'Title',
            'message'       => 'Message',
            'vibrate'       => 0,
            'content-available' => 1
        );

But vibration is still working even I set the vibrate value to 0.

Any help will be greatly appreciated. Thank you!

1 Answers1

0

Within the PushNotification.init() method you also need to set 'vibrate' to false, as it defaults to true for Android. iOS however does not have a similar setting, but setting sound to false may also work (i haven't tested this).

var push = PushNotification.init({
    android: {
        senderID: "12345679",
        vibrate: false
    },
    ios: {
        sound: false
    },
    windows: {}
});

https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md#pushnotificationinitoptions

jdtaylor
  • 334
  • 2
  • 5
  • 20
  • Setting vibrate to false in PushNotification.init() will work. Now if we set vibrate to true in payload like this. $payload = array ( 'title' => 'Title', 'message' => 'Message', 'vibrate' => 1, 'content-available' => 1 ); Is this will overwrite the declaration in PushNotification.init() which is set to false? What I am trying to achieve is disable/enable the vibrate notification base on user preferences. User preferences is save in database that is why I tried to include it in push notification payload. – user3472449 Jun 01 '16 at 09:55
  • I'm not sure off the top of my head if that would work, i don't have an environment to test that setup currently. If you find that the payload doesn't override the PushNotification.init() value what you could potentially do is make an API request from your app to retrieve the users preference, store that in localStorage, and then use that value when calling PushNotification.init() – jdtaylor Jun 02 '16 at 14:22
  • Thanks @jdtaylor! I will try your suggestion. – user3472449 Jun 03 '16 at 06:31
  • Out of interest, did you have any luck with this? – jdtaylor Jun 20 '16 at 15:24
  • Payload don't override the declaration in PushNotification.init() in my case. – user3472449 Jun 21 '16 at 06:03