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

App stops sending locations after a few days to a week #316

Closed turbobuilt closed 6 years ago

turbobuilt commented 7 years ago

Your Environment

        BackgroundGeolocation.configure({
            desiredAccuracy:100,
            distanceFilter:10,
            activityRecognitionInterval: 10*1000,
            url: "http://redacted/locations",
            stopOnTerminate:false,
            startOnBoot:true
        },function(state){
            console.log('BackgroundGeolocation initizalized ', state);
            if(!state.enabled)
                BackgroundGeolocation.start();
        });

Expected Behavior

Plugin should continue reporting locations indefinitely whenever user moves

Actual Behavior

Plugin reports location for several days, maybe a week, then stops reporting locations to server. In my last test, I installed and started the app on Monday. It reported motion fine through Saturday. From Sunday on, it has failed to report when I left the house. I did not open the app or otherwise touch it. On Sunday I went to a restaurant approximately 4 miles away, ate dinner, then left. All locations during this time went unreported.

I have noticed that it is still tracking my location, but it seems that it just isn't triggering a report. The reason this might be the case is that in the privacy part of iOS settings, it shows the purple icon after going on a walk where I was about a mile from my home at the farthest. I'm not sure why it would not be reporting my location change though.

Steps to Reproduce

This is the relevant code:

var app = angular.module('push', ['ionic', 'app.controllers'])
app.run(function ($ionicPlatform, $state) {
  $ionicPlatform.ready(function () {
    console.log('other ready running')
    if (window.cordova) {
       startBackgroundTracking();
    }
  })
})

function startBackgroundTracking() {
    if (window.BackgroundGeolocation) {
        //start background tracking service
        BackgroundGeolocation.configure({
            desiredAccuracy:100,
            distanceFilter:10,
            activityRecognitionInterval: 10*1000,
            url: "http://redacted/locations",
            stopOnTerminate:false,
            startOnBoot:true
        },function(state){
            console.log('BackgroundGeolocation initizalized ', state);
            if(!state.enabled)
                BackgroundGeolocation.start();
        });
   }
}

Context

Debug logs

Did not record my walk yesterday where I went 1 mile out and back (2017-04-03), or trip to place 4 miles away on Sunday (2017-04-02)

2017-04-01 20:29:33.003 ✅ [BackgroundTaskManager stopBackgroundTask] 81 OF (
)

2017-04-01 21:10:00.473 ⋯-[TSDBLogger db_save] Log committed

2017-04-01 21:24:52.020 ⋯-[TSDBLogger db_save] Log committed

2017-04-03 18:34:01.215 ⋯-[TSDBLogger db_delete] maxAge: 604800

2017-04-03 18:34:01.446 ⋯-[TSDBLogger db_save] Log committed

2017-04-03 19:02:50.527 ⋯-[TSDBLogger db_save] Log committed

2017-04-04 15:42:15.049 🔵-[Settings init] Settings loaded (this was when I restarted it today)
christocracy commented 7 years ago

That's all the logs you have? Not much to analyze there.

turbobuilt commented 7 years ago

Those are the only logs from the days it was supposed to report but didn't. The actual logs are way to long to post here, so I just posted the last stopBackgroundTask from april 1st, and then the logs from the days it didn't report.

christocracy commented 7 years ago

Post the logs to a separate file and link it.

christocracy commented 7 years ago

When field-testing, you should use debug: true so you can hear and see the plugin working (or not working)

turbobuilt commented 7 years ago

Here it is:

[removed for privacy]

The reason I set debug: false, was it seemed like debug:true prevented the bug from occurring. I may not have waited long enough for the bug to occur though. I can try that again for a week and see if it still works.

turbobuilt commented 7 years ago

Also I force quit the app on the first day of testing, and never reopened it.

christocracy commented 7 years ago

First thing's first, review all your event-listeners and make sure you're calling bgGeo.finish(taskId)

2017-03-28 19:58:40.015 ⚠️__45-[BackgroundTaskManager createBackgroundTask]_block_invoke FORCE KILL BACKGROUND TASK: 316, remaining time: 4.081271

2017-03-28 19:58:40.016 ⚠️__45-[BackgroundTaskManager createBackgroundTask]_block_invoke FORCE KILL BACKGROUND TASK: 317, remaining time: 4.081003

2017-03-28 19:58:40.016 ⚠️__45-[BackgroundTaskManager createBackgroundTask]_block_invoke FORCE KILL BACKGROUND TASK: 318, remaining time: 4.080741

2017-03-28 19:58:40.016 ⚠️__45-[BackgroundTaskManager createBackgroundTask]_block_invoke FORCE KILL BACKGROUND TASK: 319, remaining time: 4.080566

2017-03-28 19:58:40.016 ⚠️__45-[BackgroundTaskManager createBackgroundTask]_block_invoke FORCE KILL BACKGROUND TASK: 320, remaining time: 4.080398

2017-03-28 19:58:40.016 ⚠️__45-[BackgroundTaskManager createBackgroundTask]_block_invoke FORCE KILL BACKGROUND TASK: 314, remaining time: 4.080232

Are you subscribing to the location event?

christocracy commented 7 years ago

You denied "Motion Activity updates" permission?

2017-03-28 19:50:15.248 🎾-[SOMotionDetector startShakeDetection:] sample-rate: 0.2 | M7 DISABLED
turbobuilt commented 7 years ago

No, I am not subscribing to any location event on purpose. I was trying to keep it as bare-bones simple as possible.

turbobuilt commented 7 years ago

I just checked, and yes, I have all motion activity banned on my phone. However, I had another tester who had the same issue, and I don't think he banned motion activity updates. Still, it should work even with said motion updates disabled, right?

christocracy commented 7 years ago

It will work without Motion Activity. iOS changes to tracking mode via stationary geofence exit. Your activity-recognition won't be as good and the plugin will consume more battery.

This is interesting:

2017-04-01 20:25:35.901 
<+32.84235375,-96.70640444> +/- 2000.00m (speed -1.00 mps / course -1.00) @ 4/1/17, 8:25:35 PM Central Daylight Time

2017-04-01 20:25:35.904 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | distanceFilter: -1.0
╚═══════════════════════════════════════════════════════════

2017-04-01 20:25:35.905 - Acquiring stationary location (3 / 5)

2017-04-01 20:25:35.908 ✅ [BackgroundTaskManager createBackgroundTask]: 98

2017-04-01 20:26:16.066 ⋯-[TSDBLogger db_save] Log committed

2017-04-01 20:26:35.822 ⚠️-[TSLocationManager onStationaryLocationTimeout:] 

2017-04-01 20:26:35.823 ✅ Using last-known location <+32.83355556,-96.70142035> +/- 5.00m (speed 0.00 mps / course -1.00) @ 4/1/17, 8:22:07 PM Central Daylight Time
christocracy commented 7 years ago

Before you headed out for your 4 mile trip, the plugin created its stationary geofence at this location. Is that where you started your 4 mile trip?

turbobuilt commented 7 years ago

That is the restaurant I was at

christocracy commented 7 years ago

So you're saying the plugin failed to detect you leaving that restaurant?

turbobuilt commented 7 years ago

I'm not sure. I didn't plot the points, I just looked at general timestamps

christocracy commented 7 years ago

Subscribe to the location event and simply bgGeo.finish(taskId). The plugin needs to check there are no listeners before creating its background-task.

bgGeo.on('location', function(location, taskId) {
  bgGeo.finish(taskId);
});
turbobuilt commented 7 years ago

Darn, I think I actually went to the restaurant on saturday night not sunday. But yes, looking through the points, that is indeed the last point that was sent to the server. It didn't record me coming home, or my walk 1 mile out yesterday.

I will add in that code. Any idea why it would work for a few days in the background even without that code?

christocracy commented 7 years ago

The plugin has a fail-safe to automatically FORCE KILL BACKGROUND TASK that you fail to bgGeo.finish before iOS terminates your app. It's not hurting anything but you don't want to see those.

christocracy commented 7 years ago

So I'm confused now. What's the story now?

turbobuilt commented 7 years ago

Saturday 2017-04-01:

Monday 2017-04-03:

Today go on a walk, about 3/4 mile out, not recorded.

christocracy commented 7 years ago

I think the plugin thinks you were still in that geofence at the restaurant. I'll have to try and simulate this kind of failure.

turbobuilt commented 7 years ago

Seems about right, but I don't know why it would be doing that. I have rebuilt with debugging enabled, added the location listener and finish(taskId), and have enabled m7 tracking. I will see if I get better results.

christocracy commented 7 years ago

iOS geofences are handled at the os level. It's up to the os and your network environment to fire them. -- Snet form Gmail Mobile

turbobuilt commented 7 years ago

Do you think desiredAccuracy:100, combined with disabling motion tracking may be the issue?

christocracy commented 7 years ago

No

christocracy commented 7 years ago

Have you disabled "Background Fetch" for your app?

turbobuilt commented 7 years ago

I don't think so, but how would I know?

christocracy commented 7 years ago

Settings -> Your App -> Background App Refresh

turbobuilt commented 7 years ago

Background App refresh, and all other settings there are enabled. location is set to Always

turbobuilt commented 7 years ago

I have new failure confirmation. I downloaded your sample app https://github.com/transistorsoft/cordova-background-geolocation-SampleApp (ionic 1 branch), and gave it to a tester. The tester had the exact same issue. The sample app was in Debug mode, giving out messages. He noticed that right as he was leaving the restaurant, he got a "stop on terminate restaurant", and that was it. It did not notice him getting home. He had to restart it to re-enenable tracking. The debug image is here: http://turbobuilt.com/IMG_2471.JPG, showing him getting to the restaurant, and the last message just as he is leaving.

christocracy commented 7 years ago

looks like the app was configured to stopOnTerminate: true

christocracy commented 7 years ago

You'll get a much more pleasant debugging experience if you build the Ionic 2 version. It's the same plugin, just the UI is much much better.

turbobuilt commented 7 years ago

Ok, makes sense. I have asked the other tester to please look at the settings again. I think I just used the ionic 1 version because our app is written in ionic 1.

As for my own testing I have very strange results. For some strange reason, the GPS started saying I was in Rio de Janeiro! It said this for about a day, so I first uninstalled the app we are working on - that didn't help. Then I rebooted and it works now. I'm not sure what happened, but will reinstall our app.

christocracy commented 7 years ago

You were probably playing around with "Simulate Location" in XCode.

turbobuilt commented 7 years ago

Ah, you are right! I don't remember doing that, but I see that Rio de Janeiro is selected. You are very on top of things. Thank you!

christocracy commented 7 years ago

I've made some changes in the Premium Version that might help with your issue. You used to have access to the private repo, seems you didn't pay the yearly maintenance fee. You'll have to wait some time for the fix to appear here in the public version.

turbobuilt commented 7 years ago

All right, thank you for looking into it.

On Thu, Apr 20, 2017 at 6:49 PM, Chris Scott notifications@github.com wrote:

I've made some changes in the Premium Version that might help with your issue. You used to have access to the private repo, seems you didn't pay the yearly maintenance fee. You'll have to wait some time for the fix to appear here in the public version.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/316#issuecomment-295973457, or mute the thread https://github.com/notifications/unsubscribe-auth/AHakKDwNicez8ynnp7woHFRIMSBCxiVAks5rx-8MgaJpZM4MzaJJ .

christocracy commented 7 years ago

Latest stable release has been publish (2.7.1)

turbobuilt commented 7 years ago

Ok I will try it out. Thanks for letting me know.

christocracy commented 7 years ago

Update please.

turbobuilt commented 7 years ago

I have tried to install the latest release (I assume you meant to write 2.7.1 instead of 1.7.1).

I get a build error:

Plugins/cordova-background-geolocation-lt/CDVBackgroundGeolocation.m:35:33: Incompatible block pointer types assigning to 'void (^)(NSString __strong, NSString strong, NSDictionary *strong)' from 'void (^)(NSDictionary *__strong)'

At this code:

    bgGeo.geofenceBlock         = [self createGeofenceHandler];

which I'm guessing references this code

-(void (^)(NSDictionary *geofenceData)) createGeofenceHandler {
    return ^(NSDictionary *geofenceData) {
        if (![geofenceListeners count]) {
            return;
        }
        for (NSString *callbackId in geofenceListeners) {
            CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:geofenceData];
            [result setKeepCallbackAsBool:YES];
            [self.commandDelegate runInBackground:^{
                [self.commandDelegate sendPluginResult:result callbackId:callbackId];
            }];
        }
    };
}
christocracy commented 7 years ago
$ cordova platform remove ios
$ cordova platform add ios

rebuild.

turbobuilt commented 7 years ago

Great, it installs now! I will test it over the next several days. I have been busy on other things and had not gotten around to updating this program.

christocracy commented 6 years ago

Can this be closed?