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

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!

Related

react-native-webview high vulnerability UXSS

I started a new ReactNative app and tried to use webview for playing Youtube Video
It was ok the last time i used it but this time when i install the package i get a high vulnerability message :
" High Universal XSS in Android WebView"
More info : https://npmjs.com/advisories/1560
My questions :
can we use it despite this message or it will be rejected by the Play Store ?
otherwise do you know how to fix it ?
Or
do you know another way to do it (without using react-native-youtube)
It is good that you are security aware!
Can we use it?
I don't think Google will reject your app. In other words, we launched a few apps using react-native-webview and did not experience any problem when launching on Google Play.
This vulnerability affects React Native apps which use a react-native-webview that allows navigation to arbitrary URLs. I don't think you use the webview that way.
So, yes, I think you can use it.
How to fix it?
As found in the advisory https://npmjs.com/advisories/1560:
Ensure users update their Android WebView system component via the
Google Play Store to 83.0.4103.106 or higher to avoid this UXSS.
'react-native-webview' is working on a mitigation but it could take
some time.
So you have to be patient and wait for a fix. The way you use it is save.

How to make socket-io work even after app close

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.

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.

Detect other running iOS app using systcl

I use sysctl () function to get the process list, but is there a way to detect currently running app? My app is location based app and it runs in the background. I want to detect which app is running in foreground at certain time intervals. Is this possible at all?
I understand this kind of app behavior is forbidden by apple but I still like to try this.

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.