ios icon indicating copy to clipboard operation
ios copied to clipboard

localNotification handler does not complete when woken from background

Open edwinckc opened this issue 3 years ago • 5 comments

When a notification is received, didReceiveRemoteNotification is called with a completion handler, which is then passed to RN. However, if the user performs an action on the notification, that is handled by didReceiveNotificationResponse, which does not have a completion handler.

The RN listener for localNotification ends up being called, but the device does not wait for it to complete. This is okay when the app is in the foreground. If the app is in the background, the app gets woken up and the RN listener is started, but the RN handler does not complete before app goes to sleep again.

edwinckc avatar Jun 01 '21 20:06 edwinckc

Not very nice, but without changing the lib, you can use this little 'hack' to make it work:

https://gist.github.com/braandl/306640e2aa98392df5b654b2b35facad

best

braandl avatar Jun 07 '21 13:06 braandl

Thanks @braandl, really appreciate the help! It looks promising debugging in the simulator, but only seems to work on the second try because the first time it wakes up it's loading a new bundle from Metro. Facing some other issues with release build, will report back once I'm able to test it out on release. At the very least the initial notifications come through on cold start now thanks to your code 💯

edwinckc avatar Jun 09 '21 21:06 edwinckc

On a real device, this works for me also after re-bundling the app. From what I saw in the debugger, the native modules get invoked just normally and then the JS execution is paused until bundling is complete. Therefore I can then fetch the registered notification. But I never tested in any simulator.

braandl avatar Jun 11 '21 07:06 braandl

@braandl @edwinckc Does this work for both local notification and remote notification?? Is this the fix for getInitialNotification return null always when app launch from Coldboot?

I have tried the above gist and the app crashes with a log"libc++abi.dylib: terminating with uncaught exception of type NSException". I am no a native guy it will be great if you can help me out with this.

Appdelegate.m: https://gist.github.com/anishtr4/1d9c6aea15190aeb8a7f852f5c747be8 Appdelegate.h:https://gist.github.com/anishtr4/551d1380fcfaf9d08b854bac960e16a0

**Error log:**https://gist.github.com/anishtr4/8c87afbaff8ea7f5c5f917eb3af99a7d

anishtr4 avatar Jun 18 '21 17:06 anishtr4

I am sorry, I do not have cloud messaging in my App, so I can only speak for local notifications.

But according to Apples documentation (https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension/1845197-didreceivenotificationresponse) it will work for all of them.

braandl avatar Nov 05 '21 12:11 braandl