phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.31k stars 996 forks source link

iOS ecb callback not firing with PushNotification plugin #68

Open aaroncraigongithub opened 11 years ago

aaroncraigongithub commented 11 years ago

I've done a full write up of the problem on the PG Build forum, as I assumed to begin with that this was an issue with Build.

They have directed me to post an issue here, though, so here you go :)

http://community.phonegap.com/nitobi/topics/ios_ecb_callback_not_firing_with_pushnotification_plugin

The summary of the post is: Using more or less the boilerplate example, everything works as expected on Android. iOS calls the token handler, but does not call the ecb callback. If the app is in the background the notice is displayed in the notification area or the lock screen on iOS, but activating the app still doesn't cause the ecb handler to run.

rvanoord commented 11 years ago

I am experiencing exactly the same problem with the push notification plugin. iOS receives push notifications, but the javascript callback (ecb) is not raised.

Is there a known solution to this problem?

aaroncraigongithub commented 11 years ago

As a workaround, we've implemented a polling system on the app, using a message id in the push notification. Every push notification that DOES trigger the ecb (when the app is in the background) pings the server to say the message arrived.

When the app is in the foreground, any notifications that were never acknowledged are pulled from the server and displayed.

It's a hacky workaround, but at least the message gets through.

sirikon commented 11 years ago

What would we do to solve the issue?

sulphur commented 11 years ago

any news ?

i have the same problem and basically i can have it working one way or another but not both... For example if in function onNotificationAPN(event) {} i add eventListener 'resume' :

function onNotificationAPN(event) { document.addEventListener("resume", function(){ alert('event') }) i have my notifications working when resuming from background but not when app is active. And of course if i put this:

function onNotificationAPN(event) { alert('notification') } it works when app is active. If i use both sometimes my notification is fired two times... The second problem with event is that you need to remove it after if not during next notification it will be called twice. So to be able to remove it i need to pass function as parameter so i have no access to push event object ...

sulphur commented 11 years ago

i think it is iOS 7 releted since i just tested on 3gs iOS 6.1.2 and i don't have any problems at all

kaansoral commented 10 years ago

I've never upgraded to iOS7 - and I'm experiencing a similar issue On Android things work as expected, you can pull down the notification tray, click a notification and get the event However if iOS app is running - notification logic doesn't seem to work

zeligmanos commented 10 years ago

I'm experiencing the same issue on an iPhone 4 / iOS 7. I do receive the notifications but the ecb event is never fired so if the App is running, there is no way for me to display the notification to the user. Any workaround?

Is there some way to somehow access the incoming json payload?

lopezdonaque commented 10 years ago

Same problem here!

zeligmanos commented 10 years ago

The way it is implemented here (contrary to the documentation) it works! The code looks a bit complicated to me (I don't understand why the callback doesn't work normally but works as an object method!?!): http://labs.apt.no/push-notifications-with-phonegap-part-2/

If you use the code supplied in the link intact, will work for you and the callback will fire but through an indirect way...

lopezdonaque commented 10 years ago

After debug, I detect that jsonStr contains carriage return characters.

{"badge":"1","sound":"default","body":"","loc-key":"NEW_MESSAGE","action-loc-key":"VIEW","loc-args":"(

)",foreground:"1"}

These must be removed before call "stringByEvaluatingJavaScriptFromString".

thauser777 commented 10 years ago

We just recently moved to PhoneGap Build from PhoneGap native. Before when we used just PG native building, everything worked perfect, now with PG Build everything is working great on Android EXCEPT in iOS it doesn't appear that I'm getting the notifications when the app is in background. Foreground works fine - notification comes in and ecb fires OK.

vitaliivitko commented 10 years ago

Hi, has anyone solved this issue with PhoneGap Build. It is currently using com.phonegap.plugins.pushplugin v.2.1.1, and push notifications received in background do NOT trigger onNotificationAPN callback. Please help.

Moinkhaan commented 10 years ago

Waiting for the same....("ecb" not firing)...any news guys...???

knusperpixel commented 10 years ago

I am having some issues with this too (iOS 7.1, Phonegap 3.3.0, PushPlugin 2.2.1). Some testing seems to indicate that this is some kind of misunderstanding how this plugins really works. If I register my device for Push Notifications I am getting an device token and am able to send a push message to my device. Everything works fine, the ecb gets called. If I close the app (not just put in background) and send the message, it will arrive but no callback gets called. If I re-register with window.plugins.pushNotification.register everything works as expected again.

madebysoren commented 10 years ago

I can confirm that @reevesja2411 fix is working. I now get the callback from a background notification.

Mobiletainment commented 10 years ago

I debugged the plugin in Xcode and learned that it's working just fine. The problem is rather arised from the demo's parse-time definition of the callback function, which instead of: function onNotificationAPN(e) { ... } needs to be defined so: onNotificationAPN = function(e) { ... }

Using run-time definition instead of parse-time definition will allow the plugin to trigger the callback function via webView stringByEvaluatingJavaScriptFromString correctly when a notification arrives.

I fixed the problem in Pull Request #191

Hope this helps.

bau720123 commented 10 years ago

hi @Mobiletainment I am using PGB 3.4 with plugin 2.1.1 https://build.phonegap.com/plugins/324 I have the same problem with everybody that talk about "ecb callback not firing"

so I have change the original way

function onNotificationAPN(e) { ... }

to you mean that way

onNotificationAPN = function(e) { ... }

but still can't trigger the onNotificationAPN function so...if it is because of that the 2.1.1 is a old version,maybe one day PGB team upgrade this plugin greater than 2.1.1 (after merge from yours) will the problem will be solve ?

danielbraun commented 10 years ago

I am confirming the fix by @reevesja2411 .

danielbraun commented 10 years ago

This issue has been fixed in commit: https://github.com/phonegap-build/PushPlugin/commit/e0076130186d7d2e7fbc4c35b5ef7f0955497c48

bau720123 commented 10 years ago

wow~ thanks @danielbraun waitting for the new version "PushPlugin" release by PGB

dibari commented 10 years ago

The fix didn't seem to work for me. The JavaScript ecb callback is only executed in some situations, specifically:

Is anyone else having these results?

danielbraun commented 10 years ago

That's the behavior I get as well: if the app icon is tapped, instead of the notification banner, the handler is not called. That's the normal behavior of iOS. For example, If I load the App Store app, I see the featured section. But if I hit on the banner for "Dropbox was updated", it opens the App Store at the Updates section.

bau720123 commented 10 years ago

hi all anything update about this issue ?

Moinkhaan commented 10 years ago

I am still at same situation....notification arrives but call back is not firing... :(

karnash commented 10 years ago

onNotificationGCM dont work,,..., never firing please.. S.O.S

Moinkhaan commented 10 years ago

@karnash ...in my case onNotificationGCM(the one in Android) fires perfectly....just onNotificationAPN which doesnt fire..(in iOS).

here's how i call the functions if (device.platform == 'android' || device.platform == 'Android') { pushNotification.register(this.successHandler, this.errorHandler, {"senderID":"XXXXXXXXXXXXX","ecb":"mobile.onNotificationGCM"}); } else { pushNotification.register(this.tokenHandler,this.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"mobile.onNotificationAPN"}); } }

kaansoral commented 10 years ago

Did you guys check #221 - or other issues?

Moinkhaan commented 10 years ago

@kaansoral : I checked it. And i believe there's no problem in my message data. The onNotificationAPN doesnt fire though...

karnash commented 10 years ago

@khaanYoufoot thk..!! a lot.. but dont work.. :( y have the same code.. but im using cordova 3.5 and the last PushPlugin version. .:(

Moinkhaan commented 10 years ago

@karnash : excuse me for asking silly question...but...is your senderID correct?

you can chek by clicking the link (your id will be in url,if yu have turned cloud messaging API on) https://code.google.com/apis/console/?pli=1

karnash commented 10 years ago

yes.. i have register and have the key.. :+1:

ahmet2106 commented 10 years ago

Just checked the console in Developer Console for iOS on Safari, there is no output, so I just can underline that problem, too. Working with both iOS and Android, iOS Push notification is received in XCode Logs, but onNotificationAPN() is never called, so we cant work with that :/

mica16 commented 10 years ago

Same issue: onNotificationAPN is not fired.
Any news about it?

mica16 commented 10 years ago

ecb is not fired when I directly click on the app icon. However it well works when I click on the notification.

Any changes ?

rdbmax commented 10 years ago

Same issue ecb is not fired when app opened with icon app.

How can I give push data to javascript in this case ?

Thanks

mica16 commented 10 years ago

I managed to handle the opening using the resume method of Cordova/Phonegap. http://docs.phonegap.com/en/1.6.0/cordova_events_events.md.html#resume I specified an http call within this method to refresh data.

rdbmax commented 10 years ago

I have another problem if i launch app and i receive push ( during app is open ) i can log the push from native code but Js callback is not fired. Is it known or just my own case ?

Mechanicalee commented 10 years ago

I am also experiencing the issue on iOS where the ecb is not called when opening the app via the icon. Looking at the xcode log it looks like application didReceiveRemoteNotification in AppDelegat+notification doesn't get called for some reason. Is there a reliable work around for this? Thanks Lee

Mechanicalee commented 10 years ago

OK after further investigation it seems that this is not actually an issue and is just how iOS works. The push notification is only accessible when clicking the notification and not when clicking the app icon.

Here is a quote from Apples Push Notification Documentation:

"As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon.

If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification ."

bau720123 commented 10 years ago

hi everybody maybe 2.3.1 version solve the issue https://build.phonegap.com/plugins/1083 try it and feedback

bau720123 commented 10 years ago

hi again https://build.phonegap.com/plugins/1199 2.4.0 solved the problem

marek1 commented 10 years ago

@Mobiletainment :+1: it totally solved the problem :)

JeremyColton commented 9 years ago

I am using PG 3.6.3 on iOS7, PushPlugin 2.4.0 and my app behaves as follows:

a) app is running in the foreground ie open, it receives the payload of the notification but no notification is seen and there is no beep. Bad. Badge is updated. b) app is running in the background, it does display a notification and beeps. Badge is not updated! Pressing the notification loads the payload into the app. c) app is running in the background, a notification is displayed. Pressing the app's icon does not cause the notification's payload to be loaded into the app. Bad. Badge is not updated.

I am looking for a solution that always shows the notification just like with how notifications appear for WhatsApp and pressing the app's icon also causes the notification payload to be available to the app. Is this possible with this plugin?

t2wu commented 9 years ago

@Mechanicalee You are right about when user pressing the icon, but not the notification message, the app would not be aware of the notification. However, that was before silent notification was introduced or without using silent notification after iOS7. I think PushPlugin could have supported silent notification by implementing application:didReceiveRemoteNotification:fetchCompletionHandler. But as it currently stand, it doesn't.

allisok commented 9 years ago

hi, i have the same problem, when my app is in foreground and push has come, there is nothing happening, but in xcode concole i see that push was received.

when my app in background the push come to phone, but callback function is not fired!

cordova 3.7 , push plugin 2.4.0, ios 7+

t2wu commented 9 years ago

@allisok Always send a silent push notification. More details here. http://hayageek.com/ios-silent-push-notifications/ . Watch the WWDC video on silent push (came out two years ago for iOS7) if necessary.

Also patch the PushPlugin as instructed in this issue: https://github.com/phonegap-build/PushPlugin/issues/288

Now, as long as your app is not terminated and is running or suspended in the background, it gets awaken for a short period and you can process the message.

allisok commented 9 years ago

thank, but i need do some action, when user click on push message, instead of moment ,when push come. i try send silent push, but when app in foreground callback isn't firing

t2wu commented 9 years ago

@allisok Not sure what you mean by "user click on push message instead of moment". Anyway, it works for me when app is in the background. Provided you patch it like the poster says on issue #288. Also you have to enable remote notification in the background modes of Xcode file or the equivalent plist.

mmacmillan commented 9 years ago

@rdbmax I can duplicate this behavior if i add a field containing an array to the message payload. For example, with the following message payload, using actions, from this example will cause the plugin to receive the notification event, but not call the javascript handler:

{
    aps: { 
        alert: {
            body: 'test message!',
            actions: [
                { id: 'test-action-id', title: 'test-action' }
            ]
        }
    }
}

I am determining the plugin receives the notification event, by receiving the following console output in xcode:

2015-02-27 08:33:39.942 PushNotificationsTest[291:79047] Notification received
2015-02-27 08:33:39.943 PushNotificationsTest[291:79047] Msg: {"actions":"(
        {
        id = "test-action-id";
        title = "test-action";
    }
)","body":"test message!","action-loc-key":"View",foreground:"0"}

If I remove the actions field from the message payload, my app's javascript handler will be fired as expected. On a side note, it looks like @arzynik added #495 to introduce support for actions, which use arrays, but i haven't tested this myself.

clarklight commented 9 years ago

This is 2015 April, i am facing the same problem on Android, i am wondering if this has been fixed?? I click on the Icon, then my notification tray gets deleted, but no ECB is fired.