0

How can I format the push notification so that when it displays on the status bar it can take advantage of the local notification’s construct – show the text and hide the data?

Behavior: Push notifications display on the device's status bar when the mobile app is not running. When the user clicks on the notification on the status bar, the notification disappears and the app opens. Though this is acceptable behavior, the originating push notification was not formatted for the user to view on the status bar. How can the push notification be formatted so that it is more compatible with status bar (local notification) viewing? In other words, hide the data but show user readable text?

Plugins:

  • Push Notification: phonegap-plugin-push Local Notification
  • Local Notification: de.appplant.cordova.plugin.local-notification

.Net C# App Service code:

string xml = "<ACTION>Add</ACTION>" +
             "<UserId>" + ut.UserId + " </UserId>";
Dictionary<string, string> templateParams = new Dictionary<string, string>();
templateParams["messageParam"] = xml;
try
{
    NotificationOutcome result = await 
        hub.SendTemplateNotificationAsync(templateParams, tagId);
    config.Services.GetTraceWriter().Info(result.State.ToString());
    return result;
}

Below is my Mobile App code:

cordova.plugins.notification.local.on("click", function (notification) {
    // Notification.text - contains whatever is in messageParam
    // Notification.data - How do I format the app service code so that the
    //                     xml shows up in Notification.data?
});

Thanks for any help.

Mike
  • 136
  • 13
  • I can convert the xml to an object. How would C# convert a string to a javascript object? Also, how do I format the Web Service's templateParams? – Mike Apr 25 '17 at 12:32

1 Answers1

0

Below is my solution...

Server-Side:

Dictionary<string, string> templateParams = new Dictionary<string, string>();
templateParams["messageParam"] = xmlNotification;
templateParams["titleParam"] = "testTitle";
templateParams["dataParam"] = "this is some data";

NotificationOutcome result = await 
   hub.SendTemplateNotificationAsync(templateParams, tagId);
config.Services.GetTraceWriter().Info(result.State.ToString());

Client-Side Registration:

AzureDbSvc.client.push.register('gcm', handle, {
    mytemplate: { body: { data: { message: "{$(messageParam)}", title: "{$(titleParam)}", 
       data: "{$(dataParam)}" } }, tags: arrTags }

Client-Side Notification Handler:

    pushRegistration.on('notification', function (data) {
        ...
    });

Thanks to Jeff Sanders for providing the following documentation...

Contents of data at run time:

Debugger Quickwatch Window

Community
  • 1
  • 1
Mike
  • 136
  • 13