pmwisdom/cordova-background-geolocation-services

iOS Lock screen tracking

Closed this issue · 35 comments

I'm having some issues with tracking when the device is locked and the app is in the foreground on iOS (not tested on Android).

I have been experiencing this in my own app and thought it was perhaps an issue with my own code but I see the same issue when using your demo code in a fresh Phonegap app. Often I do not receive location updates or notifications. When the app resumes I see one "We got an BG update ...." console log. Some times it will work perfectly but I can't work out what is causing the inconsistent behaviour.

Locations seem to work perfectly when the app is pushed into the background with the home button before locking the device.

I am successfully acquiring a location before locking the device.

This is my test index.js

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);

        var output = document.getElementById("output");
        output.textContent = "Getting position...";

        //Make sure to get at least one GPS coordinate in the foreground before starting background services
        navigator.geolocation.getCurrentPosition(onSuccess);

        function onSuccess() {
            output.textContent = "Position aquired.";
        }

        //Get plugin
        var bgLocationServices =  window.plugins.backgroundLocationServices;

        //Congfigure Plugin
        bgLocationServices.configure({
            //Both
            desiredAccuracy: 20, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
            distanceFilter: 5, // (Meters) How far you must move from the last point to trigger a location update
            debug: true, // <-- Enable to show visual indications when you receive a background location update
            interval: 9000, // (Milliseconds) Requested Interval in between location updates.
            //Android Only
            notificationTitle: 'BG Plugin', // customize the title of the notification
            notificationText: 'Tracking', //customize the text of the notification
            fastestInterval: 5000, // <-- (Milliseconds) Fastest interval your app / server can handle updates
            useActivityDetection: true // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)

        });

        //Register a callback for location updates, this is where location objects will be sent in the background
        bgLocationServices.registerForLocationUpdates(function(location) {
            console.log("We got an BG Update" + JSON.stringify(location));
        }, function(err) {
            console.log("Error: Didnt get an update", err);
        });

        //Register for Activity Updates (ANDROID ONLY)
        //Uses the Detected Activies API to send back an array of activities and their confidence levels
        //See here for more information: //https://developers.google.com/android/reference/com/google/android/gms/location/DetectedActivity
        bgLocationServices.registerForActivityUpdates(function(acitivites) {
            console.log("We got an BG Update" + activities);
        }, function(err) {
            console.log("Error: Something went wrong", err);
        });

        //Start the Background Tracker. When you enter the background tracking will start, and stop when you enter the foreground.
        bgLocationServices.start();


        ///later, to stop
        //bgLocationServices.stop();
    }
};

Here is an example log from a time when tracking did not work:

2016-05-27 13:05:11.012 Hello World[3739:1422193] Apache Cordova native platform version 3.9.2 is starting.
2016-05-27 13:05:11.013 Hello World[3739:1422193] Multi-tasking -> Device: YES, App: YES
2016-05-27 13:05:11.029 Hello World[3739:1422193] Unlimited access to network resources
2016-05-27 13:05:11.042 Hello World[3739:1422193] 

Started backup to iCloud! Please be careful.
Your application might be rejected by Apple if you store too much data.
For more information please read "iOS Data Storage Guidelines" at:
https://developer.apple.com/icloud/documentation/data-storage/
To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file

2016-05-27 13:05:11.496 Hello World[3739:1422193] Resetting plugins due to page load.
2016-05-27 13:05:11.637 Hello World[3739:1422193] Finished load of: file:///var/containers/Bundle/Application/11D795EC-B0CD-4025-9E96-862A74025B35/Hello%20World.app/www/index.html
2016-05-27 13:05:11.741 Hello World[3739:1422193] THREAD WARNING: ['Geolocation'] took '21.319092' ms. Plugin should use a background thread.
2016-05-27 13:05:11.774 Hello World[3739:1422193] [LocationServices] - --------------------------------------------------------
2016-05-27 13:05:11.775 Hello World[3739:1422193] [LocationServices] -    Configuration Success
2016-05-27 13:05:11.776 Hello World[3739:1422193] [LocationServices] -        Distance Filter     5.0
2016-05-27 13:05:11.776 Hello World[3739:1422193] [LocationServices] -        Desired Accuracy    10.0
2016-05-27 13:05:11.779 Hello World[3739:1422193] [LocationServices] -        Activity Type       CLActivityType
2016-05-27 13:05:11.779 Hello World[3739:1422193] [LocationServices] -        Update Interval     5.0
2016-05-27 13:05:11.779 Hello World[3739:1422193] [LocationServices] - --------------------------------------------------------
2016-05-27 13:05:11.780 Hello World[3739:1422193] [LocationServices] - Started
2016-05-27 13:05:11.811 Hello World[3739:1422193] THREAD WARNING: ['BackgroundLocationServices'] took '30.446045' ms. Plugin should use a background thread.
2016-05-27 13:05:11.815 Hello World[3739:1422193] [LocationServices] - registerForLocationUpdates
2016-05-27 13:05:11.817 Hello World[3739:1422193] ERROR: Method 'registerForActivityUpdates:' not defined in Plugin 'BackgroundLocationServices'
2016-05-27 13:05:11.817 Hello World[3739:1422193] -[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = ["BackgroundLocationServices565512988","BackgroundLocationServices","registerForActivityUpdates",[]]
2016-05-27 13:05:16.318 Hello World[3739:1422193] [LocationServices] - App Will Resign. Enabled? true
2016-05-27 13:05:16.320 Hello World[3739:1422193] [LocationServices] - Starting Location Updates!
2016-05-27 13:05:16.409 Hello World[3739:1422193] [LocationServices] - App Suspended. Enabled? true
2016-05-27 13:05:16.412 Hello World[3739:1422193] [LocationServices] - Starting Location Updates!
2016-05-27 13:05:16.425 Hello World[3739:1422193] [LocationServices] - Got location update

AFTER RESUME…

2016-05-27 13:05:39.831 Hello World[3739:1422193] [LocationServices] - sync called
2016-05-27 13:05:39.832 Hello World[3739:1422193] [LocationServices] - locationArray has no entries
2016-05-27 13:05:39.832 Hello World[3739:1422193] [LocationServices] - Stopped Location Updates After 2.0
2016-05-27 13:05:39.832 Hello World[3739:1422193] [LocationServices] - restartUpdates called
2016-05-27 13:05:39.834 Hello World[3739:1422193] [LocationServices] - Starting Location Updates!
2016-05-27 13:05:40.032 Hello World[3739:1422193] [LocationServices] - App Resumed
2016-05-27 13:05:40.037 Hello World[3739:1422193] [LocationServices] - Stopping Location Updates!
2016-05-27 13:05:40.083 Hello World[3739:1422193] [LocationServices] - Got location update
2016-05-27 13:05:40.085 Hello World[3739:1422193] [LocationServices] - Got location update
2016-05-27 13:05:42.084 Hello World[3739:1422193] [LocationServices] - sync called
2016-05-27 13:05:42.106 Hello World[3739:1422193] [LocationServices] - bestLocation: {Optional(<+53.79545628,-1.54111949> +/- 65.00m (speed -1.00 mps / course -1.00) @ 27/05/2016, 13:05:40 British Summer Time)}

SIMILAR TO BELOW IS REPEATED EVERY 2 SECONDS...

2016-05-27 13:10:22.747 Hello World[3745:1424146] [LocationServices] - Got Location Update:  { 53.7954899420689 - -1.54113312728304 }  Accuracy: 65.0
2016-05-27 13:10:22.747 Hello World[3745:1424146] [LocationServices] - Sending Notification
2016-05-27 13:10:22.749 Hello World[3745:1424146] [LocationServices] - Stopped Location Updates After 2.0
2016-05-27 13:10:25.370 Hello World[3745:1424146] [LocationServices] - App Resumed
2016-05-27 13:10:25.370 Hello World[3745:1424146] [LocationServices] - Stopping Location Updates!
2016-05-27 13:10:25.374 Hello World[3745:1424146] [LocationServices] - Got location update
2016-05-27 13:10:27.375 Hello World[3745:1424146] [LocationServices] - sync called
2016-05-27 13:10:27.378 Hello World[3745:1424146] [LocationServices] - bestLocation: {Optional(<+53.79550998,-1.54116128> +/- 65.00m (speed -1.00 mps / course -1.00) @ 27/05/2016, 13:10:25 British Summer Time)}

Hey @3rror404 I've tried to repro this today but I couldn't. I do however see you are seeing an exception from registering for activity updates, which isn't supported on IOS. I've fixed the IOS exception if you call that function on IOS in the latest commit if you'd like to try that out.

Thanks for looking at this. I no longer see the exception in the logs so thanks for that. However I'm still getting the same issue on both of my iPhone 6's one is running iOS 9.3.1 and the other 9.3.2. Strangely it seems to work more consistently on my old iPhone 5 running 8.1.2 but I'm still experience the issue - just not quite as often.

My app is entirely reliant on your plugin so I really appreciate any help you can offer. Is there any other info I can provide to help you track this down?

@3rror404 I did test it out on an iPhone 5s with 9.3.1, so it shouldn't be that. Strange that it worked better for you on the 5 though.

So you say your using the demo code from the README? Is that correct? In that case, in your code, is the stop command immediately after the start command?

@3rror404 I'd also like you to try to set all the settings to their most intense values,

desiredAccuracy : 0, distanceFilter : 0

I'm using the code form the readme but omitting the .stop(). I've also added a success callback to the .getCurrentPosition call (the demo code actually throws an error without the callback). You can see my test code above in the "This is my test index.js" block.

I've just tested with the the most aggressive settings and unfortunately it's still the same.

Here's the log from the test:

2016-05-31 17:05:46.927 Hello World[5781:2472102] Apache Cordova native platform version 3.9.2 is starting.
2016-05-31 17:05:46.929 Hello World[5781:2472102] Multi-tasking -> Device: YES, App: YES
2016-05-31 17:05:46.934 Hello World[5781:2472102] Unlimited access to network resources
2016-05-31 17:05:46.942 Hello World[5781:2472102] 

Started backup to iCloud! Please be careful.
Your application might be rejected by Apple if you store too much data.
For more information please read "iOS Data Storage Guidelines" at:
https://developer.apple.com/icloud/documentation/data-storage/
To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file

2016-05-31 17:05:47.191 Hello World[5781:2472102] Resetting plugins due to page load.
2016-05-31 17:05:47.296 Hello World[5781:2472102] Finished load of: file:///var/containers/Bundle/Application/D98C8A52-E2D7-417D-A0F3-DDE928037A0B/Hello%20World.app/www/index.html
2016-05-31 17:05:47.352 Hello World[5781:2472102] THREAD WARNING: ['Geolocation'] took '22.061768' ms. Plugin should use a background thread.
2016-05-31 17:05:47.394 Hello World[5781:2472102] [LocationServices] - --------------------------------------------------------
2016-05-31 17:05:47.395 Hello World[5781:2472102] [LocationServices] -    Configuration Success
2016-05-31 17:05:47.396 Hello World[5781:2472102] [LocationServices] -        Distance Filter     0.0
2016-05-31 17:05:47.396 Hello World[5781:2472102] [LocationServices] -        Desired Accuracy    -2.0
2016-05-31 17:05:47.398 Hello World[5781:2472102] [LocationServices] -        Activity Type       CLActivityType
2016-05-31 17:05:47.401 Hello World[5781:2472102] [LocationServices] -        Update Interval     9.0
2016-05-31 17:05:47.401 Hello World[5781:2472102] [LocationServices] - --------------------------------------------------------
2016-05-31 17:05:47.402 Hello World[5781:2472102] [LocationServices] - Started
2016-05-31 17:05:47.420 Hello World[5781:2472102] [LocationServices] - Are we in the background? false
2016-05-31 17:05:47.433 Hello World[5781:2472102] THREAD WARNING: ['BackgroundLocationServices'] took '30.858887' ms. Plugin should use a background thread.
2016-05-31 17:05:47.456 Hello World[5781:2472102] [LocationServices] - registerForLocationUpdates
2016-05-31 17:05:47.457 Hello World[5781:2472102] [LocationServices] - Activity Updates not enabled on IOS
2016-05-31 17:05:47.457 Hello World[5781:2472102] [LocationServices] - Started
2016-05-31 17:05:47.458 Hello World[5781:2472102] [LocationServices] - Are we in the background? false
2016-05-31 17:05:56.941 Hello World[5781:2472102] [LocationServices] - App Will Resign. Enabled? true
2016-05-31 17:05:56.943 Hello World[5781:2472102] [LocationServices] - Starting Location Updates!
2016-05-31 17:05:56.995 Hello World[5781:2472102] [LocationServices] - App Suspended. Enabled? true
2016-05-31 17:05:56.997 Hello World[5781:2472102] [LocationServices] - Starting Location Updates!
2016-05-31 17:05:57.003 Hello World[5781:2472102] [LocationServices] - Got location update

AFTER RESUME...

2016-05-31 17:06:28.166 Hello World[5781:2472102] [LocationServices] - sync called
2016-05-31 17:06:28.171 Hello World[5781:2472102] [LocationServices] - locationArray has no entries
2016-05-31 17:06:28.171 Hello World[5781:2472102] [LocationServices] - Stopped Location Updates After 2.0
2016-05-31 17:06:28.171 Hello World[5781:2472102] [LocationServices] - restartUpdates called
2016-05-31 17:06:28.174 Hello World[5781:2472102] [LocationServices] - Starting Location Updates!
2016-05-31 17:06:28.380 Hello World[5781:2472102] [LocationServices] - App Resumed
2016-05-31 17:06:28.381 Hello World[5781:2472102] [LocationServices] - Stopping Location Updates!
2016-05-31 17:06:28.388 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:28.391 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:30.390 Hello World[5781:2472102] [LocationServices] - sync called
2016-05-31 17:06:30.406 Hello World[5781:2472102] [LocationServices] - bestLocation: {Optional(<+53.79549218,-1.54116049> +/- 72.86m (speed -1.00 mps / course -1.00) @ 31/05/2016, 17:06:28 British Summer Time)}
2016-05-31 17:06:30.407 Hello World[5781:2472102] [LocationServices] - Got Location Update:  { 53.7954921783816 - -1.54116049163823 }  Accuracy: 72.8604096511255
2016-05-31 17:06:30.408 Hello World[5781:2472102] [LocationServices] - Sending Notification
2016-05-31 17:06:30.409 Hello World[5781:2472102] [LocationServices] - Stopped Location Updates After 2.0
2016-05-31 17:06:37.392 Hello World[5781:2472102] [LocationServices] - restartUpdates called
2016-05-31 17:06:37.395 Hello World[5781:2472102] [LocationServices] - Starting Location Updates!
2016-05-31 17:06:37.461 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.462 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.661 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.662 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.663 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.664 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.665 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:37.710 Hello World[5781:2472102] [LocationServices] - Got location update
2016-05-31 17:06:39.462 Hello World[5781:2472102] [LocationServices] - sync called
2016-05-31 17:06:39.465 Hello World[5781:2472102] [LocationServices] - bestLocation: {Optional(<+53.79553797,-1.54115108> +/- 65.00m (speed -1.00 mps / course -1.00) @ 31/05/2016, 17:06:37 British Summer Time)}
2016-05-31 17:06:39.466 Hello World[5781:2472102] [LocationServices] - Got Location Update:  { 53.7955379683715 - -1.54115108114984 }  Accuracy: 65.0

Ah yes, I forgot about that, I'll update the readme with a callback. So you get a position back from the first getCurrentPosition? No error?

Yeah that's correct. The success callback updates a message on the screen so I know it has succeeded.

I'm not sure if this helps at all but the blue "APP NAME is using your location" status bar also doesn't appear when tracking fails.

Also, I can not reproduce this in the simulator. It works perfectly every time there.

@3rror404 Thanks for more information. Do the logs from the simulator look any different?

Specifically the:
App Will Resign and App suspend console logs, do they happen in the same order.

I'm also interested to see what happens if you build it to your phone and then immediately close it. Then start up the app fresh, and see if the same thing happens. This might be a strange interaction with building it to the phone.

OK so I'm now at home on a different computer and the simulator is also giving me inconsistent results.

Most of the time it works. Sometimes I don't receive any updates. And sometimes I receive one location and then nothing - this has never happened on a device.

Here is a log of one of these times:

2016-05-31 19:13:58.575 Hello World[2210:102961] [LocationServices] - --------------------------------------------------------
2016-05-31 19:13:58.575 Hello World[2210:102961] [LocationServices] -    Configuration Success
2016-05-31 19:13:58.575 Hello World[2210:102961] [LocationServices] -        Distance Filter     0.0
2016-05-31 19:13:58.575 Hello World[2210:102961] [LocationServices] -        Desired Accuracy    -2.0
2016-05-31 19:13:58.576 Hello World[2210:102961] [LocationServices] -        Activity Type       CLActivityType
2016-05-31 19:13:58.576 Hello World[2210:102961] [LocationServices] -        Update Interval     9.0
2016-05-31 19:13:58.576 Hello World[2210:102961] [LocationServices] - --------------------------------------------------------
2016-05-31 19:13:58.578 Hello World[2210:102961] [LocationServices] - registerForLocationUpdates
2016-05-31 19:13:58.578 Hello World[2210:102961] [LocationServices] - Started
2016-05-31 19:13:58.578 Hello World[2210:102961] [LocationServices] - Are we in the background? false
2016-05-31 19:14:00.774 Hello World[2210:102961] [LocationServices] - App Will Resign. Enabled? true
2016-05-31 19:14:00.775 Hello World[2210:102961] [LocationServices] - Starting Location Updates!
2016-05-31 19:14:00.778 Hello World[2210:102961] [LocationServices] - App Suspended. Enabled? true
2016-05-31 19:14:00.780 Hello World[2210:102961] [LocationServices] - Starting Location Updates!
2016-05-31 19:14:00.781 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:14:00.783 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:14:00.784 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:14:00.785 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:14:02.781 Hello World[2210:102961] [LocationServices] - sync called
2016-05-31 19:14:02.785 Hello World[2210:102961] [LocationServices] - bestLocation: {Optional(<+37.34747663,-122.10131879> +/- 5.00m (speed 33.39 mps / course 298.48) @ 5/31/16, 7:14:00 PM British Summer Time)}
2016-05-31 19:14:02.785 Hello World[2210:102961] [LocationServices] - Got Location Update:  { 37.34747663 - -122.10131879 }  Accuracy: 5.0
2016-05-31 19:14:02.786 Hello World[2210:102961] [LocationServices] - Sending Notification
2016-05-31 19:14:02.786 Hello World[2210:102961] [LocationServices] - Stopped Location Updates After 2.0
2016-05-31 19:14:09.781 Hello World[2210:102961] [LocationServices] - restartUpdates called
2016-05-31 19:14:09.786 Hello World[2210:102961] [LocationServices] - Starting Location Updates!

AFTER RESUME...

2016-05-31 19:17:10.173 Hello World[2210:102961] [LocationServices] - App Resumed
2016-05-31 19:17:10.174 Hello World[2210:102961] [LocationServices] - Stopping Location Updates!
2016-05-31 19:17:10.266 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:17:12.266 Hello World[2210:102961] [LocationServices] - sync called
2016-05-31 19:17:12.267 Hello World[2210:102961] [LocationServices] - locationArray has no entries
2016-05-31 19:17:12.267 Hello World[2210:102961] [LocationServices] - Stopped Location Updates After 2.0
2016-05-31 19:17:19.267 Hello World[2210:102961] [LocationServices] - restartUpdates called
2016-05-31 19:17:19.269 Hello World[2210:102961] [LocationServices] - Starting Location Updates!
2016-05-31 19:17:20.202 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:17:21.205 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:17:22.196 Hello World[2210:102961] [LocationServices] - Got location update
2016-05-31 19:17:22.204 Hello World[2210:102961] [LocationServices] - sync called
2016-05-31 19:17:22.206 Hello World[2210:102961] [LocationServices] - bestLocation: {Optional(<+37.38858496,-122.15776739> +/- 5.00m (speed 32.31 mps / course 281.25) @ 5/31/16, 7:17:22 PM British Summer Time)}
2016-05-31 19:17:22.206 Hello World[2210:102961] [LocationServices] - Got Location Update:  { 37.38858496 - -122.15776739 }  Accuracy: 5.0
2016-05-31 19:17:22.207 Hello World[2210:102961] [LocationServices] - Sending Notification
2016-05-31 19:17:22.207 Hello World[2210:102961] [LocationServices] - Stopped Location Updates After 2.0

And here it worked correctly:

2016-05-31 19:18:28.381 Hello World[2227:105153] [LocationServices] - --------------------------------------------------------
2016-05-31 19:18:28.381 Hello World[2227:105153] [LocationServices] -    Configuration Success
2016-05-31 19:18:28.381 Hello World[2227:105153] [LocationServices] -        Distance Filter     0.0
2016-05-31 19:18:28.381 Hello World[2227:105153] [LocationServices] -        Desired Accuracy    -2.0
2016-05-31 19:18:28.382 Hello World[2227:105153] [LocationServices] -        Activity Type       CLActivityType
2016-05-31 19:18:28.382 Hello World[2227:105153] [LocationServices] -        Update Interval     9.0
2016-05-31 19:18:28.382 Hello World[2227:105153] [LocationServices] - --------------------------------------------------------
2016-05-31 19:18:28.384 Hello World[2227:105153] [LocationServices] - registerForLocationUpdates
2016-05-31 19:18:28.384 Hello World[2227:105153] [LocationServices] - Started
2016-05-31 19:18:28.384 Hello World[2227:105153] [LocationServices] - Are we in the background? false
2016-05-31 19:18:30.657 Hello World[2227:105153] [LocationServices] - App Will Resign. Enabled? true
2016-05-31 19:18:30.658 Hello World[2227:105153] [LocationServices] - Starting Location Updates!
2016-05-31 19:18:30.662 Hello World[2227:105153] [LocationServices] - App Suspended. Enabled? true
2016-05-31 19:18:30.663 Hello World[2227:105153] [LocationServices] - Starting Location Updates!
2016-05-31 19:18:30.665 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:30.667 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:30.727 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:30.727 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:31.286 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:32.199 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:32.666 Hello World[2227:105153] [LocationServices] - sync called
2016-05-31 19:18:32.669 Hello World[2227:105153] [LocationServices] - bestLocation: {Optional(<+37.39771939,-122.17994381> +/- 5.00m (speed 34.93 mps / course 321.33) @ 5/31/16, 7:18:32 PM British Summer Time)}
2016-05-31 19:18:32.669 Hello World[2227:105153] [LocationServices] - Got Location Update:  { 37.39771939 - -122.17994381 }  Accuracy: 5.0
2016-05-31 19:18:32.670 Hello World[2227:105153] [LocationServices] - Sending Notification
2016-05-31 19:18:32.671 Hello World[2227:105153] [LocationServices] - Stopped Location Updates After 2.0
2016-05-31 19:18:33.201 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:34.200 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:35.200 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:36.201 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:37.204 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:38.196 Hello World[2227:105153] [LocationServices] - Got location update
2016-05-31 19:18:39.222 Hello World[2227:105153] [LocationServices] - Got location update

REGULAR UPDATES AFTER...

I'm also interested to see what happens if you build it to your phone and then immediately close it. Then start up the app fresh, and see if the same thing happens. This might be a strange interaction with building it to the phone.

Now this is interesting. If I force quit the app and open it again then lock the device it will most likely not work.
If I then force quit again, re-open, lock device, it will most likely work correctly. I can do this multiple times and it will work consistently. (Something to do with the GPS having already warmed up?)
However, if I then force quit and open a couple of other apps, re-open, lock device, it will not work again.
(GPS deactivated again?)

Hi @pmwisdom and @3rror404
am also facing this problem..Did you find any solution for that?

After sometime, my background service is stopped automatically(app is not force closed). How to fix that issue?

@Jpsankaran I'm assuming that you're talking about Android since you mentioned a background service?

Yes @pmwisdom . I am getting issue on android.Any solution for that?

@pmwisdom ..........

Am getting one more issue from this plugin.Using remote build, i have moved my project to Xcode.While opening project,i am getting following wizard
error_xcode

Then I continued to publish my ios app and install it on real device.But my IOS app is not launching after adding this plugin(working fine in Android and IOS Simulator)

I think your plugin was written in earlier version of code(swift as shown in error wizard). Please can you fix that issue or any solution.........

That issue on android has already been discussed, please search for it, or create a new issue for it, don't hijack this one.

The swift message has nothing to do with not building to your phone, press cancel on the dialog and it will not convert, I will fix that annoyance in a future release.

Hey @pmwisdom, have you had any other thoughts on this at all? Thanks

@3rror404 I've been sort of busy this past week, I do have some ideas on why this might be happening so I'll let you know when I have something for you to test.

Hi @pmwisdom. Sorry to harass you but I'm under a lot of pressure to find a solution to this. Do you think this is going to be fixable? Thanks

I wouldn't think that its unfixable. It would be really useful if you provided an example repo so I can test exactly what your testing against. I haven't been able to repro the issue your seeing, and I use my plugin for 2 production apps, and none of my users have reported the issue that I know of.

OK, Not sure if I've done this correctly but here is the app I was testing with https://github.com/3rror404/cordova-background-geolocation-services-test

@3rror404 Try the latest commit. I altered some of the start updating logic and updated swift to its newest release. I tested it on that repo and it worked 10/10 times, restarting phone, lock screen, backgrounding phone.

Hi @pmwisdom. Unfortunately I'm seeing the exact same behaviour with the latest version. It almost always does not work after going straight to the lock screen. It doesn't make a difference wether I build straight to the device or quit and reopen.

Hi @pmwisdom. I've been away for a few weeks and see you have pushed a new version (1.0.4). Unfortunately I stil have exactly the same issue. I've created a screen recording so you can see what I am talking about..

https://www.youtube.com/watch?v=xNOTdYvo1_4

As you can see, the lock screen tracking never works unless the app has been in the background before the device is locked.

If you do as I do in the video does tracking work for you? What device are you testing on?

My config:

bgLocationServices.configure({
            //Both
            desiredAccuracy: 0, // Desired Accuracy of the location updates (lower means more accurate but more battery consumption)
            distanceFilter: 0, // (Meters) How far you must move from the last point to trigger a location update
            debug: true, // <-- Enable to show visual indications when you receive a background location update
            interval: 9000, // (Milliseconds) Requested Interval in between location updates.
            useActivityDetection: false, // Uses Activitiy detection to shut off gps when you are still (Greatly enhances Battery Life)

            //Android Only
            notificationTitle: 'BG Plugin', // customize the title of the notification
            notificationText: 'Tracking', //customize the text of the notification
            fastestInterval: 5000, // <-- (Milliseconds) Fastest interval your app / server can handle updates

        });

I get the same results with useActivityDetection: true

@3rror404 Thanks for the repro, I will attempt that very case this week. What did you use to record video on your iOS device? I've been using an iPhone 5s and a 6 as my testing devices.

QuickTime Player to record then iMovie for the captions. Thanks for taking another look

Have you had chance to look at this yet mate?

@3rror404 I checked it out today, following your repo steps. Unfortunately I had to try with the simulator because I no longer own the iphones. Having said that, I still could not reproduce the problem.

Heres a video of it working on the sim, which is the same thing I saw on the iphones.
https://www.youtube.com/watch?v=0azGdIruppU&feature=youtu.be

Yeah it works in the simulator. I was recording my actual device. So you no longer have any real devices to test with?

This is a major issue for me now. I am virtually ready to release but can't because of this problem. Do you know of any other plugins out there that provide this functionality? I'm aware of Christocracy's but I don't think it provides locations at regular intervals.

I may have to bite the bullet and source a freelancer unless you think you can fix this. Unfortunately I don't really have the funds to do that.

the01 commented

maybe try setting up the bglocation inside the success callback of the first get location?

@3rror404 I'm sourcing an iOS device for next week. I thought you said it didn't work in simulator, my bad! Do you have another iOS device to test out on or have you been testing on the same device the entire time? I'm sorry the plugin isn't working for you, I'm kind of as baffled as you are as to why it isn't working.

Like I said before, i'm using this in 2 production apps and I haven't seen any drops in geolocation on iOS devices and I keep a good eye on how the geolocation system is performing because I wrote it.

Christocracy's plugin might work for you, but its using the the Significant locations library so you will have spots that it will miss / wont be activated for. But give it a try if you wish, the API is almost entirely the same on iOS so it should be pretty PnP

@pmwisdom , I have the same problem on iOS.

Steps to reproduce the problem:

  • open the app
  • lock screen (with app open)
  • the background tracking does not start

That step does not reproduce the problem:

  • open the app
  • press home button
  • the background tracking starts
  • lock screen (with app in background)
  • the background tracking keep working

The above steps to reproduce the problem does not occurs always, I have to repeat this steps normally 10 times and the problem happens.

@3rror404 , Did you get any solution to this problem?

PS: How did you log app debug output to icloud (you post some log above)?

@diegobill Sorry, I ditched Phonegap a long time ago. The log was probably from the Xcode console. I can’t remember.

I found this problem in another situation: facebook/react-native#9883