New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS message is lost on cold start #50

Closed
do34 opened this Issue Jul 29, 2015 · 21 comments

Comments

Projects
None yet
9 participants
@do34

do34 commented Jul 29, 2015

When a PG/Cordova-App is closed and started upon user's activating the PushMessage, this message is not forwarded to Host-App.

It seems that plugin (PushPlugin.m) receives message and only afterwards comes registration from Host-App. So probably because there are still no callbacks registered message gets lost.

In my app PushNotification.init is called on cordova's onDeviceReady event.

The guys from https://github.com/Telerik-Verified-Plugins/PushNotification seem to handle the problem well. The scenario works on their code.

@martinfilliau

This comment has been minimized.

Show comment
Hide comment
@martinfilliau

martinfilliau Jul 29, 2015

We are experiencing the same issue with version 1.1.1, but it seems to work ok with version 1.0.1.

We are experiencing the same issue with version 1.1.1, but it seems to work ok with version 1.0.1.

@macdonst macdonst added this to the Release 1.2.0 milestone Jul 29, 2015

@macdonst macdonst added the bug label Jul 31, 2015

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Aug 5, 2015

Member

@do34 and @martinfilliau what is the reproduction scenario for this one?

I have an app that is registered with my push service. I make sure it is not running by doing a swipe up on it in the task list in iOS. Then I send an push to the app and it shows up in the notification shade. When I click on this notification the app is started and my onNotification handler is executed with the info of the push notification.

What am I missing?

Member

macdonst commented Aug 5, 2015

@do34 and @martinfilliau what is the reproduction scenario for this one?

I have an app that is registered with my push service. I make sure it is not running by doing a swipe up on it in the task list in iOS. Then I send an push to the app and it shows up in the notification shade. When I click on this notification the app is started and my onNotification handler is executed with the info of the push notification.

What am I missing?

@martinfilliau

This comment has been minimized.

Show comment
Hide comment
@martinfilliau

martinfilliau Aug 5, 2015

@macdonst your scenario is correct, and it does work for us in version 1.0.1 but couldn't get it to work in 1.1.1. seems to be also described in #55 albeit I'm not sure which version is used.

@macdonst your scenario is correct, and it does work for us in version 1.0.1 but couldn't get it to work in 1.1.1. seems to be also described in #55 albeit I'm not sure which version is used.

@macdonst macdonst modified the milestones: Release 1.3.0, Release 1.2.0 Aug 25, 2015

@oscarabilleira

This comment has been minimized.

Show comment
Hide comment
@oscarabilleira

oscarabilleira Aug 30, 2015

Same problem here

Same problem here

@arlago

This comment has been minimized.

Show comment
Hide comment
@arlago

arlago Aug 31, 2015

I am having the same problem. The notification event is not fired in the iOS if the app was closed when the push notification was received.

arlago commented Aug 31, 2015

I am having the same problem. The notification event is not fired in the iOS if the app was closed when the push notification was received.

@greg84

This comment has been minimized.

Show comment
Hide comment
@greg84

greg84 Aug 31, 2015

I can reproduce this in version 1.2.2 - it works fine in Android but not iOS. I created a blank app and copied the code from the example/www folder into the app.

In the example app, the "card" with the notification details is only displayed if the app is open when the notification is received. If the app is not running and launched from the notification, the card with the notification details does not get displayed.

greg84 commented Aug 31, 2015

I can reproduce this in version 1.2.2 - it works fine in Android but not iOS. I created a blank app and copied the code from the example/www folder into the app.

In the example app, the "card" with the notification details is only displayed if the app is open when the notification is received. If the app is not running and launched from the notification, the card with the notification details does not get displayed.

@greg84

This comment has been minimized.

Show comment
Hide comment
@greg84

greg84 Sep 1, 2015

I think this might be a misunderstanding. It does work, but only if you tap the notification. If you just start the app it doesn't. Is this expected behaviour?

greg84 commented Sep 1, 2015

I think this might be a misunderstanding. It does work, but only if you tap the notification. If you just start the app it doesn't. Is this expected behaviour?

@oscarabilleira

This comment has been minimized.

Show comment
Hide comment
@oscarabilleira

oscarabilleira Sep 1, 2015

No, the problem apears when you tap de notification (when you tap the app icon it will never show the notification data)

No, the problem apears when you tap de notification (when you tap the app icon it will never show the notification data)

@greg84

This comment has been minimized.

Show comment
Hide comment
@greg84

greg84 Sep 1, 2015

I can now consistently reproduce the problem:

  • Close the app and lock the device.
  • Trigger a push notification.
  • Either swipe the notification on the lock screen or unlock the device and pull down notification centre, then tap the notification.
  • The didReceiveRemoteNotification method does not get called.

After this process, when the app is already running, the functionality works as expected. Until you close the app (double tap home, swipe up) and lock the device again.

Even if you kill the app, it still responds to notifications when you tap them, as long as you haven't locked the device in between.

Reading this, it could be expected functionality?!? http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user

greg84 commented Sep 1, 2015

I can now consistently reproduce the problem:

  • Close the app and lock the device.
  • Trigger a push notification.
  • Either swipe the notification on the lock screen or unlock the device and pull down notification centre, then tap the notification.
  • The didReceiveRemoteNotification method does not get called.

After this process, when the app is already running, the functionality works as expected. Until you close the app (double tap home, swipe up) and lock the device again.

Even if you kill the app, it still responds to notifications when you tap them, as long as you haven't locked the device in between.

Reading this, it could be expected functionality?!? http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user

@oscarabilleira

This comment has been minimized.

Show comment
Hide comment
@oscarabilleira

oscarabilleira Sep 17, 2015

Anything new about this issue?

Anything new about this issue?

@macdonst macdonst modified the milestones: Release 1.3.0, Release 1.4.0 Sep 22, 2015

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Oct 11, 2015

Member

@greg84 it seems that this is expected behaviour by iOS. The notification event doesn't get called until you tap on the notification.

I think you are looking for the same functionality as #93?

Member

macdonst commented Oct 11, 2015

@greg84 it seems that this is expected behaviour by iOS. The notification event doesn't get called until you tap on the notification.

I think you are looking for the same functionality as #93?

@greg84

This comment has been minimized.

Show comment
Hide comment
@greg84

greg84 Oct 11, 2015

Just to clarify, #93 is talking about the app being able to run code while the app is closed when a notification is received. In this case however, I'm talking about the app running code when it is launched from a notification after being killed by the user (i.e. the user taps the notification to launch an app that's previously been forcibly closed from the app switcher).

I'm talking specifically about the following repro steps using the example app (where cards appear when a notification is received).

  1. Open the app, trigger a notification, new card appears.
  2. Go back to home screen, lock the device, trigger a notification, tap notification, app opens and new card appears.
  3. Kill the app from the app switcher, lock the device, trigger a notification, tap notification, app opens but no new card appears.

I would expect number 3 to display a new card. It seems that this is expected behavior after the app has been forcibly closed by the user, but it's a bit strange. I'm not sure why killing the app should prevent the didReceiveRemoteNotification method from being called when the app resumes.

I could understand that if a user kills an app that runs code when a notification is received (like #93 talks about), you probably wouldn't want that to happen if you'd manually killed the app and stopped it from running. But I would still expect the method to run when I launch the app again from the notification.

As the links below explain, when a user force-closes the app, the callback method is no longer invoked.

http://stackoverflow.com/questions/18856204/applicationdidreceiveremotenotificationfetchcompletionhandler-not-called

http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user/19202487#19202487

I've been reading the iOS docs. This section talks about the didReceiveRemoteNotification delagate:

If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification. Instead, your implementation of the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.

My testing suggests that this hasn't been implemented properly. Although I might be misunderstanding how it actually works, in which case accept my apologies.

greg84 commented Oct 11, 2015

Just to clarify, #93 is talking about the app being able to run code while the app is closed when a notification is received. In this case however, I'm talking about the app running code when it is launched from a notification after being killed by the user (i.e. the user taps the notification to launch an app that's previously been forcibly closed from the app switcher).

I'm talking specifically about the following repro steps using the example app (where cards appear when a notification is received).

  1. Open the app, trigger a notification, new card appears.
  2. Go back to home screen, lock the device, trigger a notification, tap notification, app opens and new card appears.
  3. Kill the app from the app switcher, lock the device, trigger a notification, tap notification, app opens but no new card appears.

I would expect number 3 to display a new card. It seems that this is expected behavior after the app has been forcibly closed by the user, but it's a bit strange. I'm not sure why killing the app should prevent the didReceiveRemoteNotification method from being called when the app resumes.

I could understand that if a user kills an app that runs code when a notification is received (like #93 talks about), you probably wouldn't want that to happen if you'd manually killed the app and stopped it from running. But I would still expect the method to run when I launch the app again from the notification.

As the links below explain, when a user force-closes the app, the callback method is no longer invoked.

http://stackoverflow.com/questions/18856204/applicationdidreceiveremotenotificationfetchcompletionhandler-not-called

http://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user/19202487#19202487

I've been reading the iOS docs. This section talks about the didReceiveRemoteNotification delagate:

If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification. Instead, your implementation of the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.

My testing suggests that this hasn't been implemented properly. Although I might be misunderstanding how it actually works, in which case accept my apologies.

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Oct 11, 2015

Member

@greg84 just making sure. The worst part about this issue is that I'm following your reproduction scenario and in step three I do get the notification event in my sample app which creates a new card.

What version of iOS are you using?

Member

macdonst commented Oct 11, 2015

@greg84 just making sure. The worst part about this issue is that I'm following your reproduction scenario and in step three I do get the notification event in my sample app which creates a new card.

What version of iOS are you using?

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Oct 12, 2015

Member

@greg84 Please take a look at the attached video and let me know what I'm doing wrong trying to reproduce your problem.

https://dl.dropboxusercontent.com/u/887989/pushplugin/Issue50.mov

Member

macdonst commented Oct 12, 2015

@greg84 Please take a look at the attached video and let me know what I'm doing wrong trying to reproduce your problem.

https://dl.dropboxusercontent.com/u/887989/pushplugin/Issue50.mov

@greg84

This comment has been minimized.

Show comment
Hide comment
@greg84

greg84 Oct 13, 2015

@macdonst The steps you followed in the video are the same as what I'm doing. Only difference is I'm using ios 8.4.1 on an iPad. I wonder if Apple fixed it in the latest update?

greg84 commented Oct 13, 2015

@macdonst The steps you followed in the video are the same as what I'm doing. Only difference is I'm using ios 8.4.1 on an iPad. I wonder if Apple fixed it in the latest update?

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Oct 14, 2015

Member

@greg84 you, I can reproduce on 8.4.1 now to see if there is anything I can do about it.

Member

macdonst commented Oct 14, 2015

@greg84 you, I can reproduce on 8.4.1 now to see if there is anything I can do about it.

@italoayres

This comment has been minimized.

Show comment
Hide comment
@italoayres

italoayres Oct 14, 2015

What you guys use as a solution on a case where the user launched the app using the icon on menu?
I think this is most common on IOS.

What you guys use as a solution on a case where the user launched the app using the icon on menu?
I think this is most common on IOS.

@macdonst macdonst added the wontfix label Oct 27, 2015

@macdonst

This comment has been minimized.

Show comment
Hide comment
@macdonst

macdonst Oct 27, 2015

Member

I gotta give up on this one as I believe it to be a bug with iOS 8.4.1. If anyone has a fix I'd love to merge a PR.

Member

macdonst commented Oct 27, 2015

I gotta give up on this one as I believe it to be a bug with iOS 8.4.1. If anyone has a fix I'd love to merge a PR.

@macdonst macdonst closed this Oct 27, 2015

@addityasingh

This comment has been minimized.

Show comment
Hide comment
@addityasingh

addityasingh Mar 31, 2016

I have found the solution for this one. The reason for this issue is that in PushPlugin.m the callbackId property is set to nil on killing the app. As a result, the check on line#441 is not satisfied in the - (void)notificationReceived callback. The fix for the issue is to instantiate the PushPlugin class on opening the push notification every time your app starts. This can be done by registering the push notification plugin on app start.
Call the PushPlugin.init method in your javascript everytime your app starts, and this will instantiate the plugin and assign the appropriate callback and callbackid in the plugin. I have added the below code to my Ionic app's app.run() section

window.PushNotification.init({ 
    ios: {
       "badge": false,
       "sound": true,
       "alert": true,
       "clearBadge": true
   }
})

Let me know if anyone still faces this issue.

I have found the solution for this one. The reason for this issue is that in PushPlugin.m the callbackId property is set to nil on killing the app. As a result, the check on line#441 is not satisfied in the - (void)notificationReceived callback. The fix for the issue is to instantiate the PushPlugin class on opening the push notification every time your app starts. This can be done by registering the push notification plugin on app start.
Call the PushPlugin.init method in your javascript everytime your app starts, and this will instantiate the plugin and assign the appropriate callback and callbackid in the plugin. I have added the below code to my Ionic app's app.run() section

window.PushNotification.init({ 
    ios: {
       "badge": false,
       "sound": true,
       "alert": true,
       "clearBadge": true
   }
})

Let me know if anyone still faces this issue.

@ngt14

This comment has been minimized.

Show comment
Hide comment
@ngt14

ngt14 May 23, 2016

Hi @addi90 , i follow your solution but I always have this problem.
the callbackId property is nil when my app is in foreground and background but when my app closed my property is nil .

ngt14 commented May 23, 2016

Hi @addi90 , i follow your solution but I always have this problem.
the callbackId property is nil when my app is in foreground and background but when my app closed my property is nil .

@lock

This comment has been minimized.

Show comment
Hide comment
@lock

lock bot Jun 4, 2018

This thread has been automatically locked.

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.