NativeScript / push-plugin

Contains the source code for the Push Plugin.
Apache License 2.0
123 stars 45 forks source link

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

Open priyangamani opened 6 years ago

priyangamani commented 6 years ago

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 commented 6 years ago

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

notificationCallbackIOS: (message: any) => {
    console.log("Message : " + JSON.stringify(message));
}
priyangamani commented 6 years ago

I tried this callback but it's not firing.

On Fri, Apr 27, 2018, 6:57 PM Nick Iliev notifications@github.com wrote:

@priyangamani https://github.com/priyangamani use the notification callback for iOS as shown here https://github.com/NativeScript/push-plugin#using-the-plugin-in-ios:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NativeScript/push-plugin/issues/216#issuecomment-384937488, or mute the thread https://github.com/notifications/unsubscribe-auth/AFwiNR0fLYtfya7fG_8HBy4mFdNra4Lgks5tsvmygaJpZM4Tp5US .

NickIliev commented 6 years ago

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

priyangamani commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

JDillon08 commented 6 years ago

@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
        }
    }
});