Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

data.additionalData.[Object] as 'undefined' in iOS #1160

Closed
ef33zy opened this issue Aug 13, 2016 · 6 comments
Closed

data.additionalData.[Object] as 'undefined' in iOS #1160

ef33zy opened this issue Aug 13, 2016 · 6 comments
Assignees

Comments

@ef33zy
Copy link

ef33zy commented Aug 13, 2016

Expected Behaviour

I am hoping to emulate the app in foreground URL redirection described here. I expect the data.additionalData.[Object] to return the defined values in iOS as it does in Android, and I get a confirmation dialog box. Per my Sample Push Data Payload below,

$msg = array(
    'title' => $title, 'body' => $message, 'vibrate' => 1, 'sound' => 1,
    'url' => 'tasks.html',
    'page' => 'tasks page',
);
$fields = array(
    'registration_ids' => $registrationIds, 'notification' => $msg, 'priority' => 'high',
);
console.log("URL: " + data.additionalData.url);
console.log("Go to: " + data.additionalData.page);

should return:

URL: tasks.html
Go to: tasks page

Actual Behaviour

However, I do not get the dialog box as expected since the below is returned:

URL: undefined
Go to: undefined

Reproduce Scenario (including but not limited to)

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

iOS 9.3.3

Cordova CLI version and cordova platform version

PGB cli-6.3.0                                  
iOS Phonegap version  4.2.0

Plugin version

phonegap-plugin-push 1.8.0

Sample Push Data Payload

I have tried the following Payload combinations in my PHP file:
Option 1: This option works perfectly for Android

$msg = array(
    'title' => $title, 'body' => $message, 'vibrate' => 1, 'sound' => 1,
    'url' => 'tasks.html',
    'page' => 'tasks page',
);
$fields = array(
    'registration_ids' => $registrationIds, 'notification' => $msg, 'priority' => 'high',
);

Option 2:

$msg = array(
    'title' => $title, 'body' => $message, 'vibrate' => 1, 'sound' => 1,
    'additionalData.url' => 'tasks.html',
    'additionalData.page' => 'tasks page',
);
$fields = array(
    'registration_ids' => $registrationIds, 'notification' => $msg, 'priority' => 'high',
);

Option 3:

$msg = array(
    'title' => $title, 'body' => $message, 'vibrate' => 1, 'sound' => 1,
);
$additionalData = array(
    'url' => 'notificationsMovies_2.0.html',
    'page' => 'recommendations?',                                           
);
$fields = array(
    'registration_ids' => $registrationIds, 'notification' => $msg, 'priority' => 'high',
    'additionalData' => $additionalData,
);

Option 4:

$msg = array(
    'title' => $title, 'body' => $message, 'vibrate' => 1, 'sound' => 1,
);
$fields = array(
    'registration_ids' => $registrationIds, 'notification' => $msg, 'priority' => 'high',
    'url' => 'tasks.html',
    'page' => 'tasks page',
);

Sample Code that illustrates the problem

    if (data.additionalData.foreground) {
        console.log("app in foreground: " + data.message);
        cordova.plugins.notification.badge.clear(function (badge) {});
        console.log("badge cleared since app is in foreground");
        cordova.plugins.notification.badge.set(0);
        console.log("badge set to 0 (clear) since app is in foreground");

        // On clicking the notification, re-direct to the page specified in the URL.
        if (data.additionalData.url) {
            console.log("URL: " + data.additionalData.url);
            console.log("Go to: " + data.additionalData.page);
            navigator.notification.confirm(
                data.message + '. See all ' + data.additionalData.page, // message
                function onConfirm(buttonIndex) {
                    if (buttonIndex === 1) {
                        document.location.href = data.additionalData.url;
                    }
                },
                onConfirm, // callback to invoke with index of button pressed
                'tasks', // title
        ['Yes', 'Nah'] // buttonLabels
            );
        } else {
            console.log('No url in notification');
        }

    }

Logs taken while reproducing problem

       URL: undefined
       Go to: undefined
@macdonst macdonst added the ios label Aug 15, 2016
@skyprimer
Copy link

Same thing here.. Strange when you turn "notification" field into "data" and put the app on foreground / background the additional data arrives. But this time no notifications arrives when the app is on background or closed at all bec. of DATA field.. This bug needs to be fixed as soon as possible..

@macdonst
Copy link
Member

@ef33zy Try sending the following payload:

$msg = array(
    'title' => $title, 'body' => $message, 'vibrate' => 1, 'sound' => 1,
);
$data = array(
    'url' => 'tasks.html',
    'page' => 'tasks page',
);
$fields = array(
    'registration_ids' => $registrationIds, 'notification' => $msg, 'data' => $data, 'priority' => 'high',
);

Apologies for the late reply, I thought I had already send this. YMMV on this as I don't have as much control as to what GCM sends to an iOS app.

@skyprimer just as a heads up people maintaining open source projects really hate comments like This bug needs to be fixed as soon as possible. Many of us maintain projects like this out of our spare time because we see a need in the community and negative comments like that lead to burn out.

@skyprimer
Copy link

skyprimer commented Aug 19, 2016

Oh @macdonst English is not my mother language i just translate from my language to yours in my mind telling like that is not negative i'm sorry if you thought so.. I know these kinds of projects or blogs or etc comes out from spare time as i said this is bec. i do not have full control on English... We are from all around the world the project you are managing is bigger than you think :) So if you see comments like that don't think the poster of it is commanding something or got angry and yelling just might not using exact words on English :)

By the way adding another field "data" works great i did not know we can use both data and notification together.. 👍

@ef33zy
Copy link
Author

ef33zy commented Aug 20, 2016

@macdonst Thanks very much. That works like a charm :) (not like I know how charms work).

Would it be worth adding that to the documentation for the data.additionalData for iOS? as I searched high and low through the docs but didn't find the solution there. Also, like @skyprimer, I didn't know that the data in payload works for iOS.
Nonetheless thanks very much for the solution.

@ef33zy ef33zy closed this as completed Aug 20, 2016
@macdonst macdonst added the docs label Aug 26, 2016
@macdonst
Copy link
Member

re-opening to add to docs.

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants