push-plugin icon indicating copy to clipboard operation
push-plugin copied to clipboard

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

Open priyangamani opened this issue 7 years ago • 8 comments

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" }

priyangamani avatar Apr 27 '18 07:04 priyangamani

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

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

NickIliev avatar Apr 27 '18 10:04 NickIliev

I tried this callback but it's not firing.

On Fri, Apr 27, 2018, 6:57 PM Nick Iliev [email protected] 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 .

priyangamani avatar Apr 27 '18 11:04 priyangamani

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

NickIliev avatar Apr 27 '18 11:04 NickIliev

@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 avatar Apr 27 '18 11:04 priyangamani

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'?

priyangamani avatar May 02 '18 06:05 priyangamani

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!

JDillon08 avatar May 14 '18 15:05 JDillon08

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

bachras avatar Jul 21 '18 08:07 bachras

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

JDillon08 avatar Jul 25 '18 14:07 JDillon08