Page 1 of 1

pushNotificationToken in service Request parameter. How?

Posted: Wed Mar 19, 2014 10:10 pm
by Chris6743166

I'm trying to get the pushNotificationToken into a service request parameter in order to register a device on a website and therefore allow that site to send notifications to the device.

I have hit a brick wall with getting the pushNotificationToken into the token parameter. Here are some screenshots to illustrate what I've done so far:

Image

Image

Image

Can anyone help? I'm stuck!


pushNotificationToken in service Request parameter. How?

Posted: Wed Mar 19, 2014 11:08 pm
by Alena Prykhodko

Hi Chris,

Your screen shots seem to be ok.

Please be sure you have enabled "Push notifications" in "App settings",fields Sender ID and API key filled. See for more details:

Image

Besides, try to output "pushNotificationToken" localStorage variable to some label.


pushNotificationToken in service Request parameter. How?

Posted: Thu Mar 20, 2014 10:59 am
by Chris6743166

Hi,

Thanks for the reply!

Yes, push notifications are enabled. In fact, if I manually register my device on the remote website, then I can send notifications to the device. The problem seems to be that I'm not picking up pushNotificationToken.

As you can see from this screenshot, I have now added a label to the homepage as you suggest:

Image

On load, firstly, I set pushNotificationToken as a local storage variable, I then set the label value to that of the newly created pushNotificationToken local storage variable.

What happens is, the label value changes from "pushNotificationToken Label" to "pushNotificationToken".

Is it sufficient to enter "pushNotificationToken" into the value input when setting a local storage variable? Like this:

Image

Or am I doing something else wrong?

Chris


pushNotificationToken in service Request parameter. How?

Posted: Thu Mar 20, 2014 2:16 pm
by Chris6743166

I seem to have resolved the problem by running this javascript on Device Ready:

codesetTimeout(function(){

Code: Select all

 var pnt_value = localStorage.getItem('pushNotificationToken'); 

 localStorage.setItem('js_token', pnt_value); 

 wpRegisterToken.execute(); 

}, 1);/code

Strangely, I also have to have an additional invoke wpRegisterToken service instruction on page load for it to work. Not sure which one is doing the job. But it works.


pushNotificationToken in service Request parameter. How?

Posted: Thu Mar 20, 2014 7:09 pm
by Maryna Brodina

Hello!

Service invocation on page Load event would work every time page loads. If loading is after device ready event or app is running not the first time, token is already in localStorage variable and registration works without problems.
Review app logic and check if you need to do registration every time on Load event or it's better to delete service invocation from Load event.


pushNotificationToken in service Request parameter. How?

Posted: Thu Mar 20, 2014 11:21 pm
by Chris6743166

Thanks Maryna. Good point. I'll try invoking the service on Device Ready and test it out.

Chris