Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

How to receive and Handle Messages from APN in ios nativescript. #216

Open
priyangamani opened this issue Apr 27, 2018 · 8 comments
Open
Assignees
Labels

Comments

@priyangamani
Copy link

priyangamani commented Apr 27, 2018

How to retrieve and handle the payload data from the app in background & foreground (APN Message)in ios.In Payload key reference i receive multiple items.How to i check and get the data.Please give some reference.
Please give some reference.
{
"aps" : {
"alert" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
},
"badge" : 1,
},
"customKey" : "customValue"
}

@NickIliev
Copy link

@priyangamani use the notification callback for iOS as shown here:

notificationCallbackIOS: (message: any) => {
    console.log("Message : " + JSON.stringify(message));
}

@priyangamani
Copy link
Author

priyangamani commented Apr 27, 2018 via email

@NickIliev
Copy link

@priyangamani are you receiving the notifications? DO you have your APNS certificate set?

@priyangamani
Copy link
Author

priyangamani commented Apr 27, 2018

@NickIliev yes able to receive the notification .I have the APN cert.
How to handles some keys in the data object like message, title, and uses them to construct a notification entry in the tray on ios?
In android i able to retrive the payload actions but ios cannot.
application.on(application.resumeEvent, function(args) {
if (args.android) {
var act = args.android;
var intent = act.getIntent();
var extras = intent.getExtras();
if (extras) {
// for (var key in extras) {
// console.log(key + ' -> ' + extras[key]);
// }
var msg = extras.get('someKey');
}
}
if(app.ios){ //Here what i need to do?
}
});

@priyangamani
Copy link
Author

I got the push notifications are working, but I don't know how to extract the response.
So my question is how do I access the data inside of alert for the 'body' and 'title'?

@JDillon08
Copy link

I am interested in the solution for iOS, too.

Here's our current setup in Android:
A device receives a push notification while the app is closed. The push notification contains data that tells the app which page should be opened. After the push notification is tapped, the app is opened, and the resume event of the app is called. The push notification's data is read (using the code that priyangamani listed above) and the correct page is displayed. This is all working as intended.

In iOS, a device receives a push notification while the app is closed. The push notification contains the same data as an Android one (we're using Firebase to send the push notifications) but I don't know how to access that data. If the push notification is tapped, the app is opened and the homepage is displayed, but we'd prefer a different page to be displayed. How can I access the push notification's data so that we can control which page is displayed?

Thanks in advance!

@bachras
Copy link

bachras commented Jul 21, 2018

@JDillon08 could you share the code snippet how you implemented Android setup so you can open specific page. Thanks

@JDillon08
Copy link

JDillon08 commented Jul 25, 2018

@bachras Here's the code that we use to navigate to a specific page after resuming the app via tapping a push notification on an Android device:

// App resume event
application.on(application.resumeEvent, function(args) {
    if (args.android) {
        var act = args.android;
        var intent = act.getIntent();
        var extras = intent.getExtras();

        if (extras) {
            var data = extras.get('DATA_NAME');

            // Navigate to a specific page based off of data's value
        }
    }
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants