0
votes

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 ?

2

2 Answers

2
votes

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).

1
votes

a) MPNS Push notifications can operate in unauthenticated or authenticated mode. In unauthenticated mode, the number and frequency of notifications allowed through the Microsoft Push Notification Service is throttled (unauthenticated push notifications are currently limited to 500 per day, per channel).

MSDN documentation.

IBM MobileFirst supports both authenticated and non-authenticated MPNS push.

b) In case of Tag/Broadcast MPNS notifications, by default the notification appears within the application tile. For the notification to be displayed when the application is in foreground or as a toast notification add the following code to the sendBroadcastNotification() method in the adapter:

notificationOptions.settings = {};
notificationOptions.settings.mpns ={};
notificationOptions.settings.mpns.raw = {};
notificationOptions.settings.mpns.raw.payload= {'payload' : notificationText};

notificationOptions.settings.mpns.toast ={};
notificationOptions.settings.mpns.toast.text1 = 'Title';
notificationOptions.settings.mpns.toast.text2= notificationText;

Refer to the TagNotifications sample for the complete code