phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

Use same request for both iOS and Android (Using GCM) #702

Open ahlidap opened 8 years ago

ahlidap commented 8 years ago

Expected Behaviour

Use same request to GCM Service, to send push to both Android and iOS

Actual Behaviour

I was able to use same request to send push messages to both platforms some days ago, but now I can't do it anymore.

"notification" object in JSON (for iOS devices) is overriding the "data" object for Android.

Steps to Reproduce

{
    "registration_ids": ["iOSRegId","AndroidRegId"],
    "data": {
        "placeId": 407,
        "image": "http://someimage",
        "title": "Android Title",
        "style": "picture",
        "picture": "http://somePicture",
        "message": "My Message",
        "summaryText": "VMy Message",
        "actions": [{
            "icon": "",
            "title": "actionTitle",
            "callback": "myCallback"
        }]
    },
    "notification": {
        "title": "my title iOS",
        "body": "my message iOS"
    }
}

Sending this will result in receiving a notification with title "my title iOS" and message "my message iOS" on both iOS and Android

Platform and Version

Android 4.2.2, 4.4, .5.1.1

Sample Push Data Payload

Stated above

macdonst commented 8 years ago

@ahlidap yeah, that won't work. When the Android OS sees the 'notification' object in your push data it will take over and do it's own handling of the incoming push object. In order for this plugin to works it's magic, i.e. setup JS call backs properly, the push should not include a notification object. Everything should be in data.

You'll have to segment your users between iOS and Android then send separate pushes.

leonardobazico commented 8 years ago

+1

techSavvySaahil commented 8 years ago

I'm also using the same payload for both. Its working for android but not for iOS

"registration_ids" : tokens, "collapse_key":"score_update", "data" : { "message":params.alertData.message, "title" : "myapp", "pageId" : "notifications", "notId" : notId, "timeStamp" : new Date().getTime() }

macdonst commented 8 years ago

@techSavvySaahil yes, I am aware of the problem see my earlier answer. This is an enhancement I want to be able to provide.