How to make socket-io work even after app close - react-native

I have been building a chat application in react native. For the bi-directional communication i have used socket-io. Socket-io works only when the app is in foreground, it doesn't work when the app is in background or closed channel disconnects. So how do i keep channel connected even when the app is in background or closed. Is there any background services in react native.

You can use HeadlessJSTask for android to ensure a service is always working while you app is in background. However there is no such thing in iOS and also iOS is very strict with background jobs so you need to accept iOS as it is. Please update here if you find any such thing for iOS. Would be glad to learn.

Related

How to ping a device from a server and get a response with the device's location when the app is in the background using React Native

We're trying to build an app that can track the location of the device on-demand. So admins could send a ping signal and get back the current location of the device. Sort of like (find my phone). The functionality should work even if the app is in the background, when the device is locked, and even be available after a device restart without having to open the app first.
We're building the app using React Native and we were looking at some options for background services and push notifications but none seem to satisfy our needs. Any ideas?
You might be interested with this paid solution: https://www.transistorsoft.com/shop/products/react-native-background-geolocation

React Native: How to make HTTP request when app is backgrounded?

To simplify my problem: I have an ecommerce app that uses geofencing to detect when to prepare an order:
BackgroundGeolocation.onGeofence(geofence => {
this.props.prepareOrder();
});
The thing is, prepareOrder() makes an HTTP request to my server. I've noticed that it doesn't actually make the request until my app is foregrounded.
Is there a way around this? It is very likely that my app is backgrounded when they enter the geofence and I need to make a request.
======
The more complex version is here: https://github.com/redux-saga/redux-saga/issues/816. I'm using redux-sagas and it doesn't seem like yield call is being called. But I'm not sure if it's a redux-saga thing or something with making HTTP requests in the background.
Same here... It's not a redux-saga problem, it's a more general problem with ReactNative apps working in background: the JS Thread appears to be frozen when app is in background for a long time (especially on iOS when screen is shut down)
the behavior is different between iOS & android, and also depends on OS version. Still, We're building an application that needs constant geolocation in foreground & background, we tried doing it with sagas and we saw it didn't work : we would stop receiving locations after some time. Watching at our logs, we would see that all the ReactNative logs we had would stop too. Hence our wild guess on "maybe the OS stops all the ReactNative context, for energy reasons
So we moved our background code into native :
HTTP POST in a custom RN Native Module when app is in background on iOS
Headless JS on android.
(it seems to be the solution others have chosen too, like https://github.com/mauron85/react-native-background-geolocation)
it works!

React Native - can it do these things efficiently?

We use React/Redux for our web-based app in production, and it works really-really well. We've been curious about React Native, and have a few quick questions. We're looking for facts only, not opinions, and not interested in starting a debate.
In order to build our app, we would need the following:
push notifications - I see a few projects on github, but does anyone have a robust solution running in production for a real app?
background processing - what happens when this app isn't running in the foreground (does background processing run similarly as other native apps, i.e. can I go to the Apple Setting app and disable the background worker threads?
web sockets - again, I've seen a few projects on github with experimental results, and yes I've heard that "this is trivial to implement, you just have to write a poly-fill". What I want is a drop-in solution, that's well tested.
in-app purchases - has anyone connected react native to Apple's in-app purchase system.
Thanks! I realize that react-native is in early beta, but in order for us to build an app efficiently, we need to make sure these basic things are ready to go.
Push notifications are included with React Native although the API is not as mature as core APIs like the view system.
React Native actually pauses some of its work when the app is backgrounded and background processing has not been a focus yet. You would instead want to delegate work to a dispatch queue. This might work for your use case if the background processing doesn't involve application logic, which you want to keep in JS.
WebSockets work reasonably well with React Native. Several contributors have helped build up WebSocket support. Out of your four requirements, I would say that WebSockets are the best supported.
There are npm packages like react-native-in-app-utils that expose the IAP APIs.

Titanium iOS auto restart application in background once swiped off from background

I am working in an application that detects any Beacons nearby and gives and alert in the form of local notifications for iOS. I used TiBeacons library for titanium which did the work but I am right now stuck with an issue where I need to keep the Application running even when the user swipes off the application from background.
I was able to make it work in background which is the paused state,but is it possible to make it restart itself in the background when the user swipes the app from the background processes running,maybe with a delay if not promptly?? Thanks
There is no way to restart application after user removed it from a memory. This would be huge security bridge allowing developers to do lots of evil things to customers' devices.
You can run your code only when app is in foreground and background but never when it's killed.
You can try activate your app by receiving notification from Apple Notification Center Service:
The purpose of the Apple Notification Center Service (ANCS) is to give Bluetooth accessories (that connect to iOS devices through a Bluetooth low-energy link) a simple and convenient way to access many kinds of notifications that are generated on iOS devices.
The ability to detect iBeacons after the app was killed in the task switcher was only added in iOS 7.1. Also, I believe this functionality requires that beacon monitoring be set up with the app's main AppDelegate object as the CoreLocation delegate. I do not know much about Titanium, but glancing at the source, it appears it does not do this, and instead uses a different class as the CoreLocation delegate. This may explain why this does not work for you.
If my suspicion is true, you would not be able to detect after the app is killed using an unmodified version of that library.
Since I am not a Titanium expert, it would be best if someone who knows more about it could confirm or refute my suspicion.

Background app crashing current app

I'm building an app that uses the camera. As many know, the camera uses a lot of memory and often throws a memory warning.
The app works well and as expected. However, when streaming Spotify in the background, my app crashes.
Is there any way to stop/pause a background app?
in iOS, every app runs in its own sandbox environment that cannot interact with other apps which are running so there is no way your app can pass on any kind of instruction (pause/stop) to other app running in background.