Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

pushNotificationToken in service Request parameter. How?

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!

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

pushNotificationToken in service Request parameter. How?

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.

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

pushNotificationToken in service Request parameter. How?

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

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

pushNotificationToken in service Request parameter. How?

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

pushNotificationToken in service Request parameter. How?

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.

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

pushNotificationToken in service Request parameter. How?

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

Chris

Return to “Issues”