Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
turbobuilt opened this issue Apr 4, 2017 · 44 comments
Closed

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

turbobuilt opened this issue Apr 4, 2017 · 44 comments

Comments

@turbobuilt
Copy link

turbobuilt commented Apr 4, 2017

Your Environment

  • Plugin version: cordova-background-geolocation 2.4.0 "BackgroundGeolocation"
  • Platform: iOS
  • OS version: 9.3.5
  • Device manufacturer / model: iphone 6s
  • Cordova version (cordova -v): 6.5.0
  • Cordova platform version (cordova platform ls): ios 4.3.1
  • Plugin config:
        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
Copy link
Member

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

@turbobuilt
Copy link
Author

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
Copy link
Member

Post the logs to a separate file and link it.

@christocracy
Copy link
Member

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

@turbobuilt
Copy link
Author

turbobuilt commented Apr 4, 2017

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
Copy link
Author

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

@christocracy
Copy link
Member

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
Copy link
Member

You denied "Motion Activity updates" permission?

2017-03-28 19:50:15.248 🎾-[SOMotionDetector startShakeDetection:] sample-rate: 0.2 | M7 DISABLED

@turbobuilt
Copy link
Author

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

@turbobuilt
Copy link
Author

turbobuilt commented Apr 4, 2017

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
Copy link
Member

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
Copy link
Member

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
Copy link
Author

That is the restaurant I was at

@christocracy
Copy link
Member

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

@turbobuilt
Copy link
Author

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

@christocracy
Copy link
Member

christocracy commented Apr 4, 2017

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
Copy link
Author

turbobuilt commented Apr 4, 2017

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
Copy link
Member

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
Copy link
Member

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

@turbobuilt
Copy link
Author

turbobuilt commented Apr 4, 2017

Saturday 2017-04-01:
- Leave 4 miles to restaurant. It records me going there, but that's the last point in the database. Doesn't record me coming home

Monday 2017-04-03:
- go on a walk, checked on google maps I went a mile out and back. Not recorded.

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

@christocracy
Copy link
Member

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
Copy link
Author

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
Copy link
Member

christocracy commented Apr 4, 2017 via email

@turbobuilt
Copy link
Author

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

@christocracy
Copy link
Member

christocracy commented Apr 4, 2017 via email

@christocracy
Copy link
Member

Have you disabled "Background Fetch" for your app?

@turbobuilt
Copy link
Author

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

@christocracy
Copy link
Member

Settings -> Your App -> Background App Refresh

@turbobuilt
Copy link
Author

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

@turbobuilt
Copy link
Author

turbobuilt commented Apr 10, 2017

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
Copy link
Member

looks like the app was configured to stopOnTerminate: true

@christocracy
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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

@turbobuilt
Copy link
Author

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
Copy link
Member

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
Copy link
Author

turbobuilt commented Apr 26, 2017 via email

@christocracy
Copy link
Member

christocracy commented May 12, 2017

Latest stable release has been publish (2.7.1)

@turbobuilt
Copy link
Author

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

@christocracy
Copy link
Member

Update please.

@turbobuilt
Copy link
Author

turbobuilt commented May 19, 2017

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
Copy link
Member

$ cordova platform remove ios
$ cordova platform add ios

rebuild.

@turbobuilt
Copy link
Author

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
Copy link
Member

Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants