Skip to content
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

localNotification handler does not complete when woken from background #297

Open
edwinckc opened this issue Jun 1, 2021 · 5 comments
Open

Comments

@edwinckc
Copy link

edwinckc commented Jun 1, 2021

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.

@braandl
Copy link

braandl commented Jun 7, 2021

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

@edwinckc
Copy link
Author

edwinckc commented Jun 9, 2021

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 💯

@braandl
Copy link

braandl commented Jun 11, 2021

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.

@anishtr4
Copy link

anishtr4 commented Jun 18, 2021

@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

@braandl
Copy link

braandl commented Nov 5, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants