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

[Bridge] Run JavaScript Code on background notifications #3213

Closed
seidtgeist opened this issue Oct 3, 2015 · 5 comments
Closed

[Bridge] Run JavaScript Code on background notifications #3213

seidtgeist opened this issue Oct 3, 2015 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@seidtgeist
Copy link

I'm not sure there's a definitive issue for this topic yet. Is it possible to run JavaScript code in the background, for example in response to background push notifications? For my specific use case I'd like to fetch data from the network and store it in a persistent database. The app will read from the database when becoming active and update its UI.

It would also be feasible to run a different JavaScript entry point module instead of the main app.

For my specific use case I'm relying on iOS libraries that I'd rather not have to rely on and instead use the JavaScript equivalents.

@jaygarcia
Copy link
Contributor

There have been a few issues created about background execution of the JS Runloop. I speak from experience.

From what i've seen. As of current, it's definitely suspended and what i've read, I don't think there's a way to make it wake up unless so-called signals are sent to it, which React Native doesn't do.

The solution most people are finding is creating ObjC extensions to make this possible.

See this thread: #1282

@seidtgeist
Copy link
Author

@jaygarcia I think it is now possible to run arbitrary JS in response to remote push notifications, even when the phone is locked and screen is off: #1282 (comment)

Closing this unless I'm making this up.

@grabbou
Copy link
Contributor

grabbou commented Jan 25, 2016

Definitely, I am controlling music player while the app is in background - works. What's worth noting is that all intervals and timeouts are stopped by React, but - if you have some handlers registered on NativeAppDeviceEmitter - they will be called and if you setState on that, this will be respected as well (e.g. if you call some native APIs in componentWillReceiveProps).

@sodik82
Copy link

sodik82 commented Jul 22, 2016

hi guys, does someone knows - is it react native that postpone http fetch calls or is it happening on native layer?
I have IOS application with background modes Background fetch and Remote notifications. I can receive notification while the application is in background. It triggers HTTP request (via fetch api) but the result comes only after I switch application to foreground (most likely whole http request is only executed in foreground).
Is it RN "fault" (or intention :)) or am I missing some permissions on IOS level?

@kennethpdev
Copy link

@grabbou do you have a sample code snippet how you manage to execute a js while the app is in the background?

I'm building a music player too with a module that makes the app runs in the background, even lock screen. But the thing is. I was not able to update the module via JS because it's preventing JS execution for some reason.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants