react-native -v): 0.40
Sorry if I am repeating a question but I was not able to find my answer in docs.
I need my app to send the Geo location of the user (lat, long) to a server using an APi after every minute. Is it possible by using this component even app is in background or phone is locked?
Thanks in advance.
This plugin was designed over 3 years ago (it was ported from Cordova -> RN) to track first-responders in disaster zones.
The plugin contains the word "background" precisely because it's designed to operate in the background, 24h / day.
However, iOS location-services are strictly distance-based (ie: distanceFilter) -- not time-based. You do not say "I want a location ever x minutes" -- you say "I want a location every distanceFilter meters).
Android, however, does allow time-based tracking.
Read the Philosophy of Operation
Thank you for quick reply and really appreciate your details.
But if I am on iOS and phone is sitting on a table it I will not provide the get the geo location (even it is same as last) every x minute?
my application require that it need the user location every minute on the server so the backend users can see what is going on.
My only concern is iOS if it stop sending the location if the device is not in motion. Is there any way to achieve this on iOS?
If you want to kill the user's battery sending the location every minute, go ahead and use #watchPosition.
If you're planning on running #watchPosition 24h / day, you're going to kill the user's battery and they will hate you.
ok I can see you have (Moving & Stationary) state, is it possible on iOS I always keep it in moving even phone is sitting on a desk ?
Yes I know they gonna hate me, but I want to do some background processing (fetch) I tried your background timer (it is a good one) but what I am looking for is app keep running on background and do some fetch every minute and as it is not possible using the background fetch I am trying to use the geo location and on callback maybe use the fetch as well. It might kill the battery but without that (fetch) my application functionality is incomplete.
If you have any other suggestion please guide me if possible.
Thank you in advance.
You should be aware that the plugin includes my react-native-background-fetch plugin as a dependency. This plugin implements the iOS "Background Fetch" api, which typically awakens a suspended app about every 15 min, providing exactly 30s of bg time, which you can use to execute this plugin's #getCurrentPosition method.
This is a much more battery-efficient solution to periodically fetching the current position.
Expecting to send the location to your server every minute, 24h day is completely naive to the physical reality of the battery constraints of mobile devices.
Yes I already tried it, but my application has to talk to server every minute otherwise it kills the user session in the background and cause issues for reporting that is how the background app is working.
I know I should use background fetch and I did try it but my app cannot wait for 15 minutes.
if I kill a session after 8 hours will that help? means stop the geo location tracking after 8 hours if no interaction in last 8 hours?
but my application has to talk to server every minute otherwise it kills the user session
You can't design mobile apps like a desktop web app. You need to redesign your session constraints to cater to mobile -- not cater your mobile app to satisfy your session constraints of your server.
But be my guest: Try it out and see for yourself how quickly you kill the battery. You'll find it's completely unsatisfactory.
I'm running a watchPosition right now on my iPhone 6s. It's 6:26 and I have 100% battery.
ok I am going to add it for now, problem is our backend is a third party service and we have to work with that API like that no other choice right now until unless they willing to change the user tracking.
For this version we have to do this, and please let me know how much battery it consume in an hour if you testing as we are on the same timezone.
Thank you again
I did a test on my iPhone 5 last night. didn't touch it. Set a #watchPosition at every minute.
Starting at 100% at Midnight, 60%at 7:00am.
Burned 40% battery in 7 hours, while sleeping at night.
ok Thank you so much for that information I think I can live with that because the structure of that app is to use it like that.
But right now I am facing a problem, look at my code:
BackgroundGeolocation.configure({
// Geolocation Config
desiredAccuracy: 0,
stationaryRadius: 25,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 1,
// Application config
debug: true, // <-- enable for debug sounds & notifications
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
// HTTP / SQLite config
url: 'http://192.168.0.2/SwitchAPICall?d=test',
autoSync: true, // <-- POST each location immediately to server
// params: { // <-- Optional HTTP params
// "auth_token": "maybe_your_server_authenticates_via_token_YES?"
// }
}, function(state) {
console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
BackgroundGeolocation.watchPosition(function(location) {
console.log('- Watch position: ', location);
}, function(errorCode) {
alert('An location error occurred: ' + errorCode);
}, {
interval: 20000 // <-- retrieve a location every 5s.
});
if (!state.enabled) {
BackgroundGeolocation.start(function() {
console.log("- Start success");
});
}
});
what I did I just build the app using the Release scheme and run it on iPhone, but after 3 minutes it stop working, like I stop getting API calls.
Do you have any guess why?
Are you watching the XCode logs?
I just disconnect the phone to make sure I can watch it as live app.
I suggest you run it in plugged into XCode and monitor it.
On Fri, Feb 17, 2017 at 8:35 AM, Aamir Munir notifications@github.com
wrote:
I just disconnect the phone to make sure I can watch it as live app.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/transistorsoft/react-native-background-geolocation/issues/204#issuecomment-280650823,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA6l06IOf2BSU47K8iNU2minwgWxkLWks5rdaI1gaJpZM4MDpJy
.
--
Chris Scott
Transistor Software http://www.transistorsoft.com
8:44: 53%
If I were actually using my phone, checking email, using browser. My battery would be nearly dead.
well if it drain 50% in 8 hours I am good with that because I confirm with the user and they said ok for now.
This is not a public application but for a business backend that is why we are good for now. But I really appreciate your test result.
One more question: what if I do not need all these notifications?
Read the docs. debug: false
ok sorry I missed that and if I want to use the same component on android do I have to get the license?
if I want to use the same component on android do I have to get the license?
4:06: 26% (has not been unlocked yet)
23:11: 1%. Almost 24 hours (without using phone).
there is no way to make a conditional, which is the user when he wants to share the location and when to stop sharing it?
@JorgeLoaiza12 I have no idea what you mean.
Most helpful comment
23:11: 1%. Almost 24 hours (without using phone).