Push notification to Windows 8.1 Universal Apps

Comments

2 comments

  • Avatar
    Max Konev

    Are you sure you are using the latest Windows 8 SDK? If you are using Universal app for Windows/Windows Phone 8.1 you will need to use Windows 8 (WNS) Pushwoosh SDK for both platforms. It is located here:
    https://github.com/Pushwoosh/pushwoosh-windows-8-sdk

    The code should be exactly the same for all platforms:
    https://github.com/Pushwoosh/pushwoosh-sdk-samples/blob/master/Native/Win8/Win8JS/js/default.js

    var service = new PushSDK.NotificationService.getCurrent("YOUR_PUSHWOOSH_APP_ID");
    
    service.ononpushaccepted = function (args) {
        //code to handle push notification
        //display push notification payload for test only
        var md = new Windows.UI.Popups.MessageDialog(args.toString());
        md.showAsync()
    }
    
    service.ononpushtokenreceived = function (pushToken) {
        //code to handle push token
    }
    
    service.ononpushtokenfailed = function (error) {
        //code to handle push subscription failure
    }
    
    service.subscribeToPushService();
    

    Also don't forget to handle launch push notification:

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            showProgress();
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated)
            {
                // TODO: This application has been newly launched. Initialize
                // your application here.
    
                //Handle start push
                PushSDK.NotificationService.handleStartPush(args.detail.arguments);
    
  • Avatar
    Max Konev

    Also please note that with this approach Windows Phone 8.1 and Windows 8.1 devices will subscribe under "Windows 8" platform. You can differentiate them by using os_version tag.

Please sign in to leave a comment.