transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

ios device motion change unusuality #583

Closed novaknole closed 6 years ago

novaknole commented 6 years ago

Your Environment

Expected Behavior

after bggeo.start(), and after that, moving 200-300 meters,it should start tracking .

Actual Behavior

i am using your background-location plugin and your method getcurrentposition() function. when bggeo.start() happened and i moved 300 meters , it didn't start tracking automatically. i was moving at low speed because of traffic. but the thing is, i have a view where on each page refresh,i call your method getcurrentposition() . when i moved 300 meters and nothing happened,i refreshed the page and it called getcurrentposition() ,after that it started tracking,what i mean is maybe getcurrentposition() does the job . i tried 4-5 times and it never worked itself,until i refreshed the page and invoked getcurrentposition() function. as soon as this happened, motionchange event fired and it changed from false to true.

what really is important, it's working all fine on simulator ios and simulator is set so that it's moving with a car speed :35 . why is it working on simulator without any errors and not on my device.i googled and i found people with this problem but with no answer.i can't provide logs right now ,but maybe you can guess what happens

Steps to Reproduce

this is my configure options. maybe i need to change something. 1.locationAuthorizationRequest: 'Always', desiredAccuracy: 0, distanceFilter: 10, stationaryRadius: 10, activityRecognitionInterval:10000, stopOnTerminate:false, startOnBoot:true, debug: true, 2. 3. 4.

Context

Debug logs

christocracy commented 6 years ago

See Debugging Wiki and provide plugin's logs.

novaknole commented 6 years ago

when debugging, i should be moving with my phone?

christocracy commented 6 years ago

The plugin stores 3 days worth of logs in its database (with logLevel: bgGeo.LOG_LEVEL_VERBOSE. Go for a field-test then fetch the logs. Attach the file here in this issue.

novaknole commented 6 years ago

when debugging,it prints so quickly iphone's all logs and i can't even see it :)

novaknole commented 6 years ago

self.bgGeo.configure({ // Geolocation config locationAuthorizationRequest: 'Always', desiredAccuracy: 0, distanceFilter: 10, stationaryRadius: 10, activityRecognitionInterval:10000, stopOnTerminate:false, startOnBoot:true, debug: true, // <-- Debug sounds & notifications. }, function(state) { // This callback is executed when the plugin is ready to use. alert("gio"); self.bgGeo_enabled = true; }); self.bgGeo.setConfig({logLevel: self.bgGeo.LOG_LEVEL_VERBOSE, function() { console.log("Changed logLevel success"); }});

like this?

christocracy commented 6 years ago

Did you actually read all of this? You're not understanding.

novaknole commented 6 years ago

yes i read it and i asked you if i put that setconfig code on the correct place. after #configure

christocracy commented 6 years ago

all config params can provided to #configure. #setConfig is merely a method to change the plugin's configuration after you've called #configure. #configure is called only once.

Please learn to use syntax-highlighting with code. If you don't syntax highlight, I don't read it.

christocracy commented 6 years ago

And stop using alert when debugging. Your app is going to lock up if the app is booted in the background and tracking will fail.

iOS can and will terminate your app when the OS requires memory. When the device is detected to be moving, iOS will reboot your app in the background, where there's nobody to click the [OK] button. Since Javascript's window.alert is a blocking operation, your app will effectively be locked up until the user launches the app into the foreground to click [OK].

novaknole commented 6 years ago

thank you. so give you the proper logs, i should have my iphone plugged in, and moving with a car. after some time, i will see the log files and post it here ?

christocracy commented 6 years ago

You don't need your phone plugged in. Every log-entry is inserted into the plugin's own SQLite log database.

novaknole commented 6 years ago

where do i see the log file? i thought i would go to xcode->devices->little triangle->here is the logs .

christocracy commented 6 years ago

What does this say? Is there something unclear there?

novaknole commented 6 years ago

I understand that i should write

bgGeo.getLog(function(log) {
  console.log(log);
});

but where does console.log print it? how do i get a file to send you

christocracy commented 6 years ago

Where else? The Safari Javascript Developer Console

If you don't like that, use the #emailLog method.

novaknole commented 6 years ago

bggeo.log

novaknole commented 6 years ago

take a look. soon, i will try to use a car , in 20-30 minutes and i will upload new logs

novaknole commented 6 years ago

that's the final one. bg-location.log

christocracy commented 6 years ago

What would you like to know about this log? There's ~1.5 hours of tracking here. Nothing unusual.

I'm going to get you to sync your locations to my public tracking server. Are you using Ionic 1 or Ionic 2+? Install cordova-plugin-device if you haven't got it installed already. I will give you further instructions once you tell Ionic version.

novaknole commented 6 years ago

ionic 3.19.0 👍 is it gonna help? thing is, sometimes it doesn't work ,i mean tracking.but lately,i tried it again and it worked, the unusual thing was i am not using #configure http request to put data to my server,i just have this: bggeo.on('location',callbackfn,failure') function callbackfn(location){ //put data to my server } but this code stopped working as soon as i terminated the app,it was working in background but it never put anything to my server. then i opened the app and it quickly put all time coordinates ,maybe it remembered all the callback and made it happen as soon as app opened.

as i said,it worked lately,but i don't even know if it works when i try it tomorrow.because i am sure code is absolutelly correct 👍

christocracy commented 6 years ago

Install cordova-plugin-device.

Add the url and params as shown in this gist

Use url: 'http://tracker.transistorsoft.com/locations/novaknole so I can view your tracking.

novaknole commented 6 years ago

thank you chris. It's night over here and i will try to do it tomorrow morning and i will let you know .

novaknole commented 6 years ago

before i leave, if i use #configure http url , how can i get coordinates in it?

url: "http://your.server.com/locations", method: "POST", autoSync: true, maxDaysToPersist: 3, headers: { // <-- Optional HTTP headers "X-FOO": "bar" }, params: { // <-- Optional HTTP params "latitude":'what to put here' "longitude":'what to put here', }

i didn't find the answer in the docs.

christocracy commented 6 years ago

novaknole commented 6 years ago

Hello again ,Chris . I've been testing your plugin all day and here are what questions appeared on my mind and if you could just provide answers for them so that I understand them ,I'd be delighted. The reason why I don't understand these specifics could be because I am not familiar with ios system.

Maybe some people will need it to know and these questions are very famous because any one will have these questions when developing on ios. I am buying your premium account,i just wanted to know answers for these questions before doing that.

1) I launched the app for the first time and bggeo started. I remember reading in your docs, that for ios, the one has to move 200-300 meters so that tracking can start. but in my case, it took 4-5 minutes and probably 2000-4000 meters . but it started . why? can i think that it's working properly?

2) I terminated the app . i was waiting for it to start booting in background and it even took 9-10 minutes and notification came up : booted in background after 10 minutes and it didn't start moving,because when booted in background,i was still and as soon as it came,i started moving. i moved even 500 meters but it never started tracking.so I got over it and i will test it again ,but is it normal? boot time 9-10 minutes and then never starting tracking? what do you think?

3) imagine I launched the app and it works ,tracking is going on. and i changed the permission to never from always. it stopped tracking,then i changed it from never to always. should it continue tracking even if app is in background? or do i have to open the app again?

4) imagine app is in background, and i rebooted the device. will it continue itself tracking after rebooting ?

5)what if app is launched or is in background, for both situations,if internet connection is gone and comes again, will it continue tracking immediatelly or do i have to move again 2000-4000 meters?

Thank you . Just very important to me if you could explain to me answers for these questions.without them i am stuck and can't continue writing code . on simulator,it happens so fast ,booting in background,starting tracking and so on .

novaknole commented 6 years ago

and if app is booted in background,does it ever stop being there until user opens the app and bggeo.stop() happens? does it matter if i change permissions or internet is gone and comes back,app stays in background booted and it will engage tracking again?

christocracy commented 6 years ago

I launched the app for the first time and bggeo started. I remember reading in your docs, that for ios, the one has to move 200-300 meters so that tracking can start. but in my case, it took 4-5 minutes and probably 2000-4000 meters . but it started . why? can i think that it's working properly?

200 meters is typical. The plugin has placed a geofence around the last know location. When the device exits that geofence, iOS will awaken your app in the background and the plugin will begin tracking a location every distanceFilter meters. It's completely up to iOS to detect the geofence exit (and can depend upon the nature of the network environment (eg: cell-towers, proximity of Wifi signals).

I terminated the app . i was waiting for it to start booting in background and it even took 9-10 minutes and notification came up : booted in background after 10 minutes and it didn't start moving,because when booted in background,i was still and as soon as it came,i started moving. i moved even 500 meters but it never started tracking.so I got over it and i will test it again ,but is it normal? boot time 9-10 minutes and then never starting tracking? what do you think?

Same as above. It's completely in the operating-system's hands to detect when the device has exited the stationary geofence. You will have to test in a variety of different locations.

imagine I launched the app and it works ,tracking is going on. and i changed the permission to never from always. it stopped tracking,then i changed it from never to always. should it continue tracking even if app is in background? or do i have to open the app again?

It will continue tracking. It does not require user intervention. You can easily verify this in the iOS simulator.

imagine app is in background, and i rebooted the device. will it continue itself tracking after rebooting ?

Yes. The plugin is always monitoring a geofence around the last known location. iOS handles geofences at the OS level. Once a geofence is being monitored, it is always monitored, in spite of app terminate / device reboot. When a geofence exit occurs, iOS will always launch your app in the background to service that event.

5)what if app is launched or is in background, for both situations,if internet connection is gone and comes again, will it continue tracking immediatelly or do i have to move again 2000-4000 meters?

Internet connection has nothing to do with geolocation.

if app is booted in background,does it ever stop being there until user opens the app and bggeo.stop() happens? does it matter if i change permissions or internet is gone and comes back,app stays in background booted and it will engage tracking again?

The key to the plugin is the "geofence" around the last known position. This geofence is always being monitored, regardless of app terminate / device reboot. When that geofence is exited, iOS relaunches your app in the background to service that event and the plugin resumes tracking. Period. When your app is relaunched, the plugin is going to analyze the motion-activity. If the device-motion API says the device is moving, the plugin will initiate tracking immediately.

novaknole commented 6 years ago

thank you chris,finally i feel confident. so you say , it's always remembered in background until i use bggeo.stop(), what if user decides to stop the app from background? iphone doesn't have task manager so that one can turn it off forever. as i understand,your plugin is always in background .how does one stop it? he has to go to settings and turn off background -refresh? that's the last question and we can finish this issue

christocracy commented 6 years ago

The only way to stop the plugin is by executing the #stop method.

Disabling Background Refresh will not affect tracking.

novaknole commented 6 years ago

That's all I guess. I am kind of ready to take it to production level. I will notify you soon. do whatever you think is right :leave this closed ,but i hope i can always see this url so that in the future,i will read your answers if needed