JS Metro app is not receiving push notifications

Currently, I am in the process of integrating push notifications into a JS Metro app. After registering for push notifications and obtaining a Channel URI, I update it in my locally hosted WCF service if it is new. Within my service, I authenticate with WNS to receive the necessary access-token and other details. Subsequently, I send a request to the Channel URI with the access-token in the header. The response typically indicates that the "badge", "tile", and "toast" notification requests have been received.

Despite this, I am not receiving any notifications in my JS Metro app. Below is the code I am using to register for push notifications and to listen for them.

var push = Windows.Networking.PushNotifications;
var promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();
var channel;

function RegisterPNWin() {
try {
    push = Windows.Networking.PushNotifications;
    promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();

    promise.then(function (ch) {
        channel = ch;
        channel.addEventListener("pushnotificationreceived", notificationReceived);           
        var uri = ch.uri;
        var expiry = ch.expirationTime;

 // I also update the Channel URI on my WCF service here         
    });
} catch (e) { }
}

function notificationReceived(e, args) {
var notificationTypeName = "";
var notificationPayload;
switch (e.notificationType) {
    // Getting the toast, tile, or badge notification object and displaying the XML content.
    case pushNotifications.PushNotificationType.toast:
        notificationTypeName = "Toast";
        notificationPayload = e.toastNotification.content.getXml();
        break;
    case pushNotifications.PushNotificationType.tile:
        notificationTypeName = "Tile";
        notificationPayload = e.tileNotification.content.getXml();
        break;
    case pushNotifications.PushNotificationType.badge:
        notificationTypeName = "Badge";
        notificationPayload = e.badgeNotification.content.getXml();
        break;
    case pushNotifications.PushNotificationType.raw:
        notificationTypeName = "Raw";
        notificationPayload = e.rawNotification.content;
        break;
}
}

I would appreciate any insights on why this issue is occurring. Additionally, I am seeking recommendations on the best approach to implement push notifications in Windows 8 JavaScript Metro Apps. Do I need to include a background task to listen for push notifications?

Any code samples or guidance on this matter would be greatly helpful.

Thank you.

Answer №1

Please note that to enable push notifications in your project, you must set the property "ToastCapable = Yes" in the "Application" tab of the Package.appxmanifest file.

I hope this information is helpful to you.

Thank you, Joy Oyiess Rex

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to identify the top five elements that are most frequently occurring in the array?

I've successfully found the element that appears the most in an array, but now I'm facing a new challenge where I need to identify the top 5 elements that appear most frequently. Here is the array: [ "fuji", "acros", &q ...

What is the process for removing a range of keys from indexeddb?

I need help deleting keys that start with tracklist/RANDOM_STRING and 'songBook/RANDOM_String'. I attempted to do this using IDBKeyRange but I am struggling to understand how it works. The documentation I referred to was somewhat confusing: Mdn ...

When using NextJS <Link, mobile users may need to tap twice to navigate

Whenever I use the NextJS <Link tag on my mobile device, I notice that I have to double-tap for the link to actually route to the desired page. Take a look at the code snippet below: <Link href="/methodology" passHref={true} ...

Tips for implementing personalized command buttons in Kendo Grid with AJAX request utilizing JavaScript

I am struggling with implementing custom command buttons in a Kendo grid that makes an AJAX call using JavaScript to call a web API post action with dynamic parameters (start, stop, restart) behind button clicks. datasource dataSource = new ken ...

The issue with the full postback in the updatepanel is triggered by utilizing JavaScript on the button's onclick event within

During my testing, I encountered an issue with buttons inside a repeater within an update panel. When adding asyncpostback triggers for the buttons using <Trigger></Trigger>, an error is generated indicating that the button could not be found. ...

The Plugin.FirebasePushNotification in Xamarin.Forms did not activate the refresh token

I have encountered an issue while trying to implement remote notifications in my Xamarin.Forms mobile app. The notifications work flawlessly on the Android platform after completing all the required settings in Firebase and uploading the necessary files. H ...

Determine whether a directive possesses a specific attribute

Here is my current code snippet: <my-directive></my-directive> I am trying to include a ternary operation within it like this: {{ $scope.my-option ? 'YES' : 'NO' }} Is it possible to achieve the desired result by adding ...

The proper way to cancel useEffect's Async in TypeScript

I'm facing an issue with this straightforward example: useEffect(() => { axios.get(...).then(...).catch(...) }, [props.foo]) warning: can't perform a react state update on an unmounted component After some investigation, I found this ...

Retrieving Distinct Values in CouchDB

In my database, there are documents that represent different rooms. Each room has properties like "floor" and "hotel", among others. What I need to do is fetch all the floors associated with a specific hotel from the database. Something like getAllFloorsOn ...

Exporting an HTML table to Excel while excluding any hidden <td> elements

I have a web application with an HTML table that displays data to users. I wanted to export the table to Excel and found a jQuery code for it. However, the exported data includes information that is hidden in the table. Is there a way to export the tabl ...

The terminal does not recognize the nodemon command

My goal is to automate server reloads using nodemon. I have successfully installed it locally and set the start command as nodemon app.js with this code: "scripts": { "start": "nodemon app.js" } Initially, everything was running smoothly. However, ...

The path specified as "react-native/scripts/libraries" does not exist in the file

I've been troubleshooting an error on Github - https://github.com/callstack/react-native-fbads/issues/286. After cloning the repository and running it, I discovered that the error persisted. I am currently updating packages to investigate why this rec ...

Problem Alert: Click Event Not Functioning on Generated Links

Take a look at these two code snippets. Despite other jQuery functions in the same JS file working fine on the UL element, nothing seems to be happening with these. Is there something obvious that I am missing? <ul id="activityPaganation" class="paga ...

Changing position of element upon appearance of span in React

Currently, I am working with React and facing an issue where a span element appears whenever a user hovers over a text element. The problem is that the existing text shifts leftwards when the span appears (to the right of the text). The desired behavior ...

What could be causing the malfunction of this Ajax conditional dialog?

Can anyone help me troubleshoot this code? I've been trying to fix it for a while now, making multiple changes, but still can't find the solution. If you have any ideas please let me know, I haven't seen any errors in the console. The fir ...

Adjust the x and y coordinates of the canvas renderer

Manipulating the dimensions of the canvas renderer in Three.js is straightforward: renderer = new THREE.CanvasRenderer(); renderer.setSize( 500, 300 ); However, adjusting the position of the object along the x and y axes seems more challenging. I've ...

How to keep text always locked to the front layer in fabric.js without constantly bringing it to the front

Is it possible to achieve this functionality without using the following methods? canvas.sendBackwards(myObject) canvas.sendToBack(myObject) I am looking to upload multiple images while allowing them to be arranged forward and backward relative to each o ...

Placing a group of input fields and a button based on the data-id attribute of the element

I have a form that appears when a button is clicked, and the save button saves input values into an object. Is there a more efficient way to write this function if I need to create 9 more buttons with different data-id attributes (e.g. data-id="2" and so ...

JavaScript regular expressions only recognize certain characters

When submitting a form, I need to validate a field and ensure that only specific characters are allowed. The permitted characters include: a-z A-Z 0-9 % . " ' & - @ # $ * / + = [ ] ! I attempted to use the following regex for validation: var r ...

Tips for Implementing Command.CanExecute in a Nested Control

Below is the layout setup code: Window.xaml <Button Name="btn_Next" Command="NextPage">Next</Button> <ContentControl Name="contentControl1" > <Binding ElementName="MainWindow" Path="CurrentPage"/> </ContentControl> ...