简体   繁体   中英

Windows Phone 8 Receiving raw Push Notification issue

I am unable to receive raw notification on my WindowsPhone8.

Followed : https://github.com/barryvdh/PushPlugin/#uccb-wp8-only

Able to get toast notification. In my app toggle is happening like below.

Case 1: If I comment ecb able to get both raw and toast but not channel uri.

Case 2: If I won't comment ecb able to get toast and channel uri but not raw

My code as follows:

if (device.platform == "Win32NT") {
        console.log("called");

            pushNotification.register(
                channelHandler,
                errorHandler,
                {
                    "channelName": "channelName",
                    "ecb": onNotificationWP8,
                    "uccb": channelHandler,
                    "errcb": jsonErrorHandler
                });
        }
        else {
            console.log("not called");
        }
    }


function channelHandler(event) {
    var uri = event.uri;
    console.log("UUUUURRRRRRRRRRRIIIIIIIII  :" + uri);
}

function errorHandler(e) {
}

function jsonErrorHandler(error) {
    $("#app-status-ul").append('<li style="color:red;">error:' + error.code + '</li>');
    $("#app-status-ul").append('<li style="color:red;">error:' + error.message + '</li>');
}

function onNotificationWP8(e) {
    console.log("notification called");
    if (e.type == "toast" && e.jsonContent){
        pushNotification.showToastNotification(successHandler, errorHandler,
        {
            "Title": e.jsonContent["wp:Text1"], "Subtitle": e.jsonContent["wp:Text2"], "NavigationUri": e.jsonContent["wp:Param"]
        });
    }

    if (e.type == "raw" && e.jsonContent) {
        alert(e.jsonContent.Body);
    }
}

Tried with error and trail methods. Please suggest what might went wrong.

The issue observed does not appear to be related to Worklight at all. From the description and the code snippet, you are bypassing Worklight client SDK and server completely , and using a custom Cordova Push plugin. The custom plugin's working in your application should be analyzed to understand the variance in behaviour.

Since you are not using Worklight Push at all, you can try disabling it and check if this helps your case.

To do this, navigate to the config.xml . This will be located in apps/YourAppName/WindowsPhone8/native/Resources folder.

Look for :

<feature name="Push">
    <param name="wp-package" value="Push" />
</feature>

Change this to:

<feature name="Push">
    <param name="wp-package" value="Push" />
    <param name="onload" value="false" />
</feature>

On the query regarding Worklight API:

There are no Worklight APIs that return Channel URI. When using Worklight SDK for Push, all this is done automatically and hidden from the user. Even with a Push Adapter in place, it is not possible to obtain the channel URI as there no APIs published to obtain this information.

Finally it got solved by adding Coding4Fun.Toolkit.Controls.dll

And some code updation in PushPlugin.cs

using Coding4Fun.Toolkit.Controls; using System.Windows.Threading;

void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) {

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            string msg = string.Empty;
            foreach (var item in e.Collection)
            {
                if (item.Key == "wp:Text1")
                {
                    msg = item.Value;
                }
            }

            MessageBox.Show(msg, "Notification", MessageBoxButton.OK);

        });
    }

My heart-full thanks to Rajith who helped me to make it happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM