Search code examples
windows-phone-8notificationsibm-mobilefirst

How to configure Non-authenticated push notification for windows phone 8 in worklight


I have configured push notification in Android and IOS, and it's works perfectly. but when I configured Non-authenticated push notification for windows phone 8 in worklight, it's not working.I follow the below MobileFirst document to run push notification for windows Phone 8:

https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/#setupWP8

Also i want to know, for subscription based push notification, which notification is recommended for windows phone 8 i.e. Non-authenticated push or Authenticated push?

Below is my code:

adapter.js

function submitNotification(userId, notificationText){
var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);

if (userSubscription==null){
    return { result: "No subscription found for user :: " + userId };
}
var notification={};
notification.MPNS={};
var badgeDigit = 1;

var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
notification.MPNS.toast={};
notification.MPNS.toast.text1 = "Toast title";
notification.MPNS.toast.text2 = "Toast content";
WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);

WL.Server.notifyAllDevices(userSubscription, notification);


return { 
    result: "Notification sent to user :: " + userId 
};
}

application-descriptor.xml

<windowsPhone8 version="1.0">
    <uuid>5747-54938-fjhg-f459-844h-fhkj</uuid>
</windowsPhone8>

Please help me on windows phone 8 push notification.

++++++++++++++++++++++++++++++Update Question+++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ After adding push sender id in "application-descriptor.xml". push notification is working on windows phone8. but facing problem to receive broadcast notification on windows phone8.

broadcastAdapter.js

function sendBroadcastNotification(applicationId, notificationText) { 
var notificationOptions = {}; 
notificationOptions.message = {}; 
notificationOptions.message.alert = notificationText; 
WL.Server.sendMessage(applicationId, notificationOptions); 
return { 
result : "Notification sent to all users." 
 }; 
}

client side code in main.js:

if(WL.Client.Push){ 
WL.Client.Push.onMessage = function (props, payload) { 
navigationFromNotification = true; 
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " +    JSON.stringify(props), [ { 
text : 'Close', 
handler : function() { 
WL.SimpleDialog.show("Brodcast Notifications", "Application notification data: " + JSON.stringify(payload), [ { 
text : 'Close', 
handler : function() { 
window.location.href="#/home/2"; 
 } 
}]); 
 } 
}]); 
}; 
}

Am I need to add anything to receive broadcast Notification on windows phone8 ?


Solution

  • The documentation you have linked to clearly mentions to add an empty pushSender element, and as can be seen in your code snippet from application-descriptor.xml - you did not do that. Basically, you did not configure your application to use push notifications(!).

    <windowsPhone8 version="1.0">
        <uuid>auto-generated by the platform</uuid>
        <pushSender /> 
    </windowsPhone8>
    

    Authenticated or not authenticated push is not related to user-based subscription.
    You can use either one. The only limitation by MS is that non-authenticated is limited to 500 messages per day, whereas authenticated is not limited (and more secure).