Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

Is it safe to call pushwoosh.onDeviceReady() multiple times? #328

Closed CodeWithOz closed 4 years ago

CodeWithOz commented 4 years ago

Hi, I'd like to know if there are any harmful effects to calling pushwoosh.onDeviceReady() multiple times within the app. This was already done in my code base by someone else, but I'm not able to verify why it was done. So I'd like to know if there may be some reason behind it that I'm not aware of, or if there are harmful side-effects that were not taken into account when this was done. Thanks.

wfhm commented 4 years ago

Hey @CodeWithOz,

Multiple calls should not really affect anything - these calls will use the same singletons and set values for the same parameters, however, you can safely remove all the calls of the method except for just one - you just have to make sure it is called prior to calling any other Pushwoosh plugin method or triggering any notification-based callback on the very first run.

CodeWithOz commented 4 years ago

@wfhm thanks! One more thing. The repeated code is actually structured like this:

    var pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");
    pushNotification.onDeviceReady({
        projectid: "12345678901",
        appid: "SOME-VALUE"
    });

So it's the same singleton that gets returned every time cordova.require("pushwoosh-cordova-plugin.PushNotification") is called, correct?

wfhm commented 4 years ago

@CodeWithOz,

Yes, it should be fine. You can also refer to the sample below for examples of using particular methods of the Pushwoosh plugin, including onDeviceReady:

https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/blob/master/Cordova/www/js/index.js