Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
110 stars 139 forks source link

registerDevice is not giving the same object on success callback #174

Closed enda closed 8 years ago

enda commented 8 years ago

Hello guys,

When I do a simple registerDevice(function(data) { console.log(data); });, on Android I get a correct push token, but not on iOS where I get an object like that:

`{"type":"7","pushBadge":"1","pushSound":"1","enabled":"1","deviceToken":"xxxxxx","pushAlert":"1"}`

and no push token :(

How can I get one on both device ?

ghost commented 8 years ago

Hi,

Push token is the same as deviceToken

enda commented 8 years ago

The deviceToken is an UUID giving by the device, instead of pushToken which is a string giving by GCM or APNS, so the pushToken can change depending on the app you are, and not the deviceToken.

The documentation here http://docs.pushwoosh.com/docs/registerdevice of registering a device need a push_token, and a hwid (deviceToken), so nope, they are logically not the same, and even if, the API should return the same type of object independently of the OS.

shaders commented 8 years ago

deviceToken is push token, see: https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/blob/master/src/ios/PushNotification.m#L180

To get UUID check this method: https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/blob/master/src/ios/PushNotification.m#L46

enda commented 8 years ago

Hello @shaders,

thanks for the details, I now better understand the difference.

So maybe the bug is only that the result of the method registerDefice of the API between iOS and Android are different ? (an object in one side, and a string in the other one).

In my way, I will fix it by testing if my result is of type string or object, but it don't look natural...

Thanks,

Jerome

shaders commented 8 years ago

You are right, iOS and Android return different values here. I agree they should return values the same way, I'll put this into the backlog.

mouchimotte commented 8 years ago

+1 :D Needed here too

DimanAM commented 8 years ago

Fixed in 6.0.0

shql commented 8 years ago

Hola!

I recently included the Pushwoosh plugin with ionic plugin add pushwoosh-cordova-plugin

And it installed version 5.1.3. I came across the problem above and handled the callback as per device type.

pushwoosh.registerDevice(
    function(status) {
        var pushToken;
        if(ionic.Platform.isIOS()) {
            pushToken = status.deviceToken;
            // ...
        } else if(ionic.Platform.isAndroid()) {
            pushToken = status.split(':');
            pushToken = (pushToken.length > 1) ? pushToken[1] : null;
            // ...
        }
    },
    function(error) {
        // What happens on error?
        console.error(error);
    }
);

How would I know if I should use 6.0.0 now and if it is stable?

I am just unsure now if I should try it again with the newer version.

Thanks for an oppinion! ✌️

DimanAM commented 8 years ago

Push notification token is passed as status.pushToken in registerDevice success callback for all platforms since 6.0.0. Please check the new documentation and sample code.