christocracy / cordova-plugin-background-geolocation

Sophisticated, battery-conscious, cross-platform background-geolocation with motion-detection
http://transistorsoft.github.io/cordova-background-geolocation
492 stars 742 forks source link

iOS: 'CDVLocation.h' file not found #4

Closed 23tux closed 10 years ago

23tux commented 10 years ago

Hi,

I installed your plugin with cordova plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git on cordova 3.3.0-rc.1. Deploy target is iOS 7. When I open the project in XCode, and try to compile, I get the following error:

/Users/user1/tracker/platforms/ios/tracker/Plugins/org.transistorsoft.cordova.background-geolocation/CDVBackgroundGeoLocation.m:6:9:
'CDVLocation.h' file not found

I tried adding the org.apache.cordova.geolocation plugin. Here I can compile everything in XCode, but then when I start the app, it throws the following error in the javascript console in the file cordova.js:79:

module org.transistorsoft.cordova.background-geolocation.BackgroundGeoLocation already defined

After that, the deviceready event isn't fired (because of the error). I hope, you can help me, to get this running. I'd love to use your plugin ;)

23tux commented 10 years ago

Update:

I also found out, that the window.plugins.backgroundGeoLocation is present, but doesn't have a function configure. It's just an empty JS object.

christocracy commented 10 years ago

Sorry, I did a bad commit.

Re-install it. Got me out of bed for that one :)

Snet form my iPhone

On Feb 10, 2014, at 3:53 AM, Hubert Hölzl notifications@github.com wrote:

Hi,

I installed your plugin with cordova plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git on cordova 3.3.0-rc.1. Deploy target is iOS 7. When I open the project in XCode, and try to compile, I get the following error:

/Users/user1/tracker/platforms/ios/tracker/Plugins/org.transistorsoft.cordova.background-geolocation/CDVBackgroundGeoLocation.m:6:9: 'CDVLocation.h' file not found I tried adding the org.apache.cordova.geolocation plugin. Here I can compile everything in XCode, but then when I start the app, it throws the following error in the javascript console in the file cordova.js:79:

module org.transistorsoft.cordova.background-geolocation.BackgroundGeoLocation already defined After that, the deviceready event isn't fired (because of the error). I hope, you can help me, to get this running. I'd love to use your plugin ;)

— Reply to this email directly or view it on GitHub.

akshayakrsh commented 10 years ago

@christocracy just tried it...didnt work. got the following error in xcode:

screen shot 2014-02-10 at 5 17 55 pm

christocracy commented 10 years ago

Right, this is related to my latest addition of debugging sounds for life-cycle events.

Top of CDVBackgroundGeoLocation.m

import <AudioToolbox/AudioToolbox.h>

That worked for me and off I went on my merry way. I'll see what I can find. Perhaps there's another Cordova plugin which is properly linking this which I'm using and you're not. Such as the core Cordova Notification plugin, are you using that?

On Mon, Feb 10, 2014 at 5:48 AM, Akshaya notifications@github.com wrote:

@christocracy https://github.com/christocracy just tried it...didnt work. got the following error in xcode:

[image: screen shot 2014-02-10 at 5 17 55 pm]https://f.cloud.github.com/assets/1169337/2124972/3a644ee8-9249-11e3-8430-19ba3a32421b.png

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34623073 .

Chris Scott Transistor Software http://www.transistorsoft.com

akshayakrsh commented 10 years ago

Solved it using this http://stackoverflow.com/questions/11919923/2-errors-when-calling-audioservicesplaysystemsound

23tux commented 10 years ago

@christocracy Yes, I'm using the notification plugin org.apache.cordova.core.dialogs. I can't find any new commits, and re-installing didn't help.

christocracy commented 10 years ago

Yes, looking at the core CDVLocation.m source, I see they're a little more careful about using AudioServices.

static void playBeep(int count) {

SystemSoundID completeSound;

NSURL* audioPath = [[NSBundle mainBundle] URLForResource:

@"CDVNotification.bundle/beep" withExtension:@"wav"];

#if __has_feature(objc_arc)

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)audioPath,

&completeSound);

#else

    AudioServicesCreateSystemSoundID((CFURLRef)audioPath,

&completeSound);

#endif

AudioServicesAddSystemSoundCompletion(completeSound, NULL, NULL,

soundCompletionCallback, (void*)(count-1));

AudioServicesPlaySystemSound(completeSound);

}

On Mon, Feb 10, 2014 at 6:00 AM, Chris Scott christocracy@gmail.com wrote:

Right, this is related to my latest addition of debugging sounds for life-cycle events.

Top of CDVBackgroundGeoLocation.m

import <AudioToolbox/AudioToolbox.h>

That worked for me and off I went on my merry way. I'll see what I can find. Perhaps there's another Cordova plugin which is properly linking this which I'm using and you're not. Such as the core Cordova Notification plugin, are you using that?

On Mon, Feb 10, 2014 at 5:48 AM, Akshaya notifications@github.com wrote:

@christocracy https://github.com/christocracy just tried it...didnt work. got the following error in xcode:

[image: screen shot 2014-02-10 at 5 17 55 pm]https://f.cloud.github.com/assets/1169337/2124972/3a644ee8-9249-11e3-8430-19ba3a32421b.png

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34623073 .

Chris Scott Transistor Software http://www.transistorsoft.com

Chris Scott Transistor Software http://www.transistorsoft.com

christocracy commented 10 years ago

Thanks @Aksaya, I see the problem now comparing with Cordova's org.apache.cordova.dialogs.

Push coming soon.

On Mon, Feb 10, 2014 at 6:03 AM, Hubert Hölzl notifications@github.comwrote:

@christocracy https://github.com/christocracy Yes, I'm using the notification plugin org.apache.cordova.core.dialogs. I can't find any new commits, and re-installing didn't help.

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34624210 .

Chris Scott Transistor Software http://www.transistorsoft.com

christocracy commented 10 years ago

Ok, both of you, go ahead and re-install the plugin.

On Mon, Feb 10, 2014 at 6:08 AM, Chris Scott christocracy@gmail.com wrote:

Thanks @Aksaya, I see the problem now comparing with Cordova's org.apache.cordova.dialogs.

Push coming soon.

On Mon, Feb 10, 2014 at 6:03 AM, Hubert Hölzl notifications@github.comwrote:

@christocracy https://github.com/christocracy Yes, I'm using the notification plugin org.apache.cordova.core.dialogs. I can't find any new commits, and re-installing didn't help.

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34624210 .

Chris Scott Transistor Software http://www.transistorsoft.com

Chris Scott Transistor Software http://www.transistorsoft.com

akshayakrsh commented 10 years ago

ok...I got the plugin to install and run fine. But with the app in background, the process always exits at:

if (bgTask != UIBackgroundTaskInvalid) { NSLog(@" Abort: found existing background-task"); return; }

any idea?

23tux commented 10 years ago

@christocracy Thanks a lot! Now I can compile and run, but it seems, that the callbacks aren't triggered. Beside that, I get a deprication warning:

/Users/user1/tracker/platforms/ios/tracker/Plugins/org.transistorsoft.cordova.background-geolocation/CDVBackgroundGeoLocation.m:413:22: 'startMonitoringForRegion:desiredAccuracy:' is deprecated: first deprecated in iOS 6.0
akshayakrsh commented 10 years ago

+1 to @23tux

christocracy commented 10 years ago

Don't worry about the deprecation warning. I pushed that in last weekend. I noticed later that sending desiredAccuracy to the region-monitoring system is deprecated. I merely need to remove #desiredAccuracy from that method-call and that warning will go away.

On Mon, Feb 10, 2014 at 6:39 AM, Hubert Hölzl notifications@github.comwrote:

@christocracy https://github.com/christocracy Thanks a lot! Now I can compile and run, but it seems, that the callbacks aren't triggered. Beside that, I get a deprication warning:

/Users/user1/tracker/platforms/ios/tracker/Plugins/org.transistorsoft.cordova.background-geolocation/CDVBackgroundGeoLocation.m:413:22: 'startMonitoringForRegion:desiredAccuracy:' is deprecated: first deprecated in iOS 6.0

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34626828 .

Chris Scott Transistor Software http://www.transistorsoft.com

christocracy commented 10 years ago

Voila, go ahead and re-install again.

deprecation warning gone.

On Mon, Feb 10, 2014 at 6:39 AM, Hubert Hölzl notifications@github.comwrote:

@christocracy https://github.com/christocracy Thanks a lot! Now I can compile and run, but it seems, that the callbacks aren't triggered. Beside that, I get a deprication warning:

/Users/user1/tracker/platforms/ios/tracker/Plugins/org.transistorsoft.cordova.background-geolocation/CDVBackgroundGeoLocation.m:413:22: 'startMonitoringForRegion:desiredAccuracy:' is deprecated: first deprecated in iOS 6.0

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34626828 .

Chris Scott Transistor Software http://www.transistorsoft.com

christocracy commented 10 years ago

Which callbacks aren't triggered? Show me you javascript code.

On Mon, Feb 10, 2014 at 6:39 AM, Hubert Hölzl notifications@github.comwrote:

@christocracy https://github.com/christocracy Thanks a lot! Now I can compile and run, but it seems, that the callbacks aren't triggered. Beside that, I get a deprication warning:

/Users/user1/tracker/platforms/ios/tracker/Plugins/org.transistorsoft.cordova.background-geolocation/CDVBackgroundGeoLocation.m:413:22: 'startMonitoringForRegion:desiredAccuracy:' is deprecated: first deprecated in iOS 6.0

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-34626828 .

Chris Scott Transistor Software http://www.transistorsoft.com

akshayakrsh commented 10 years ago

Still getting - Abort: found existing background-task, this then blocks the callbacks from triggering.

Code:

 function onDeviceReady() {
      // start listening "pause" and "resume" events and give them specific callbacks
      document.addEventListener( "pause", onPause, false );
      document.addEventListener( "resume", onResume, false );

      var callback = function(location) {
         // HTTP to your server.
         var position = {
             coords: {
                         latitude: location.latitude,
                         longitude: location.longitude
                        }
            }

            sendPositionToServer(position); //does ajax call
      };

     window.plugins.backgroundGeoLocation.configure(callback, errorHandler, {
                 stationaryRadius: 50,  // meters
                 distanceFilter: 50     // meters
      });
  }

  function onPause() {
     // Disable cordova
     navigator.geolocation.clearWatch(watchId);

      // Enable background geolocation
      window.plugins.backgroundGeoLocation.start();
  }

  function onResume() {
    // Disable background geolocation
    window.plugins.backgroundGeoLocation.stop();

    // enable cordova
     watchId = navigator.geolocation.watchPosition(onLocationSuccess, errorHandler,gpsOptions);
  }
christocracy commented 10 years ago

Please reformat your code example.

23tux commented 10 years ago

I have this code from your readme:

var bgGeo = window.plugins.backgroundGeoLocation;
var callback = function(location) {
  $.ajax({
    url: 'http://10.0.0.100:3000/admin',
    dataType: "jsonp",
    callback: function() {
      console.log("fetch complete")
      // Must inform native plugin the task is complete so it can terminate background-thread and go back to sleep.
      bgGeo.finish();
    }
  });
};

var failCallback = function(event) {
  console.log(event);
}

bgGeo.configure(callback, failCallback, {
  stationaryRadius: 10, // meters
  distanceFilter: 10 // meters
});

// Enable background geolocation
bgGeo.start();
// Disable it
bgGeo.stop();

I activated background modes Location Updates and Background Fetch in XCode. On my local server, I watch the access log, and everytime a get is performed, it shows me that in the log files.

When I send the app into background with the home button, nothing happens. When I try to simulate the GPS position in XCode (Debug -> Simulate Location in the top menu), nothing happens.

I'm kinda confused, so it would be great if you can help. Furthermore, I have some questions:

christocracy commented 10 years ago

Well, I hope you're not running that exact code from my README, since:

  // Enable background geolocation
  bgGeo.start();
  // Disable it
  bgGeo.stop();  // <---------- You don't want this here:  that would stop it right after you started it.

Also, try adding debug: true when you execute #configure.

bgGeo.configure(callback, failCallback, {
    stationaryRadius: 10, // meters
    distanceFilter: 10, // meters
    debug: true   // <--- Adds life-cycle sounds
  });
23tux commented 10 years ago

No, I tried it with, and without the bgGeo.stop(); same behaviour in both cases.

akshayakrsh commented 10 years ago

@christocracy reformatted code in the same post. Git sometimes gives a hard time doing that. Please have a look.

akshayakrsh commented 10 years ago

@23tux Can you check if in xcode you see "Abort: found existing background-task" log when your app enters the background mode? I think you and I are facing the same issue.

christocracy commented 10 years ago

@23tux Show me your logs from the point right after you pause.

Here's mine: 2014-02-10 07:26:18.267 VirtualBadge[1047:60b] - onSuspend 2014-02-10 07:26:18.282 VirtualBadge[1047:60b] [D] -[UALocationService appDidEnterBackground] [Line 127] Location service did enter background 2014-02-10 07:26:18.299 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation suspend (enabled? 1) 2014-02-10 07:26:18.300 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation setPace 0, stationaryRegion? 0 2014-02-10 07:26:18.404 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:18.407 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 65.000000 2014-02-10 07:26:18.413 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:18.430 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 65.000000 2014-02-10 07:26:18.437 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:18.438 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 65.000000 2014-02-10 07:26:18.442 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:18.443 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 65.000000 2014-02-10 07:26:19.223 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:19.226 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 10.000000 2014-02-10 07:26:19.512 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:19.512 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 10.000000 2014-02-10 07:26:20.513 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 07:26:20.515 VirtualBadge[1047:60b] - Acquiring stationary location, accuracy: 10.000000 2014-02-10 07:26:20.520 VirtualBadge[1047:60b] - CDVBackgroundGeoLocation createStationaryRegion (20.640212,-87.068780) 2014-02-10 07:26:20.550 VirtualBadge[1047:6e03] 20.640217,-87.068779

23tux commented 10 years ago

@christocracy @akshayakrsh When in foreground mode, I don't get any debug information. When entering the background mode, XCode tells me this

2014-02-10 14:26:30.737 tracker[1864:60b] - CDVBackgroundGeoLocation suspend (enabled? 1)
2014-02-10 14:26:30.746 tracker[1864:60b] - CDVBackgroundGeoLocation setPace 0, stationaryRegion? 0
akshayakrsh commented 10 years ago

@christocracy here are my logs:

started when state=1 2014-02-10 18:36:59.754 LocTrack[53507:70b] - CDVBackgroundGeoLocation start (background? 2) 2014-02-10 18:36:59.754 LocTrack[53507:70b] - CDVBackgroundGeoLocation setPace 0, stationaryRegion? 0 2014-02-10 18:36:59.755 LocTrack[53507:70b] - CDVBackgroundGeoLocation suspend (enabled? 1) 2014-02-10 18:36:59.755 LocTrack[53507:70b] - CDVBackgroundGeoLocation setPace 0, stationaryRegion? 0 2014-02-10 18:36:59.861 LocTrack[53507:70b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 18:36:59.861 LocTrack[53507:70b] - Acquiring stationary location, accuracy: 5.000000 2014-02-10 18:36:59.862 LocTrack[53507:70b] - CDVBackgroundGeoLocation createStationaryRegion (42.288231,-87.952480) 2014-02-10 18:36:59.865 LocTrack[53507:7b0b] 42.288231,-87.952480 2014-02-10 18:36:59.865 LocTrack[53507:70b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0) 2014-02-10 18:36:59.865 LocTrack[53507:70b] Abort: found existing background-task 2014-02-10 18:40:05.594 LocTrack[53507:70b] - CDVBackgroundGeoLocation stopBackgroundTask (remaining t: 4.998186)

christocracy commented 10 years ago

There's nothing wrong with "Abort: found existing background-task". Background-tasks are tricky business. That merely means that the plugin has executed your callback already. In your javascript, you must be sure to execute bgGeo.finish() when all your javascript business is complete. That will end the native background-task and make way for another to be executed.

christocracy commented 10 years ago

@23tux location-updates are not being fired. Have you got Cordova's GeoLocation plugin installed? It looks to me like you haven't accepted the "Do you wish to allow App access to your location?".

akshayakrsh commented 10 years ago

@christocracy I didnt really get it, how does the event cycle work? As I understand its like:

  1. App enters background mode -> bgGeo.start() (stop cordova's plugin to avoid conflicts)
  2. App keeps on detecting locations and sending ajax calls (this can go as long as the app is in the background)
  3. User opens app -> call bgGeo.stop() and let cordova's plugin take it from here.
christocracy commented 10 years ago

@akshayakrsh Incorrect.

Either Big Brother is watching you bgGeo.start() or he's not bgGeo.stop.

call bgGeo.start() just once.

You need not start/stop on pause/resume.

when you do bgGeo.stop(), Big Brother is no longer following you, ever.

christocracy commented 10 years ago

@akshayakrsh your logs look good but be careful: Are you executing bgGeo.finish() when your Ajax request is complete? If you don't, ios is going to crash your app. Background-tasks are tricky business -- you must tell the native plugin when your javascript is done so that it can wrap up and complete the background-job.

akshayakrsh commented 10 years ago

aah ok. So I just need to call bgGeo.start() once perhaps in app initialization method and every time, my app goes to background - the background monitoring will start automatically? I jst have to call bgGeo.finish() method in my callback? (I had forgotten this earlier, as you pointed...I'm bad at following instructions sometimes ;)).

  1. I just need toggle cordova's geolocation method when the app goes in foreground or background, right? Since, I need to track the location even when the app is open.
  2. Hypothetically, if I do bgGeo.stop() once and then later bgGeo.start() again...wouldnt resume location tracking in the background?
christocracy commented 10 years ago
  1. sure. I don't even bother toggling Cordova' geolocation, I have it running on a timer though, at once / min. You could disable it when you go into bg, reenable in fg.
  2. bgGeo.start(), bgGeo.stop() is like the power-button. bg-tracking is either ON or OFF. When it's ON, it always begins tracking your user, whenever the plugin sees the "pause" event. when the plugin is OFF, no tracking in bg occurs, ever.
akshayakrsh commented 10 years ago

bgGeo.finish() did the job. Let me test the other use cases with your code, will update you soon.

w.r.t to #2 above...does it also disable itself automatically on seeing the "resume"?

Good work dude!

christocracy commented 10 years ago

It does disable automatically on resume. Don't be afraid of looking at the native source CDVBackgroundGeoLocation.m. @see #start, #stop, #onSuspend, #onResume. It's pretty easy to follow.

23tux commented 10 years ago

+1 @christocracy & @akshayakrsh this also helped me ;)

But I still can get it to work. I'm not sure, when to call bgGeo.start(). I think when the app goes into background mode. But how can I detect, if the app is in background mode?

And can you answer this question for me?

christocracy commented 10 years ago

@23tux Call bgGeo.start() right after bgGeo.configure({}).

The native plugin has listeners for "pause", "resume" events. It knows when the app has gone into the background. You need not worry about managing bgGeo in your javascript "pause", "resume" events.

When the user doesn't want to be tracked anymore in background, they'll want to have bgGeo.stop() called.

23tux commented 10 years ago

Ah, thank you.

But do I only get this in the logfiles (as mentioned in my comment above), instead of more information, as you get, when switching to background mode?

2014-02-10 14:26:30.737 tracker[1864:60b] - CDVBackgroundGeoLocation suspend (enabled? 1)
2014-02-10 14:26:30.746 tracker[1864:60b] - CDVBackgroundGeoLocation setPace 0, stationaryRegion? 0

And I also need to track the position, when the app is in foreground. How can I determine, when the app comes to foreground / background? So that I can start, the watchPosition handler?

christocracy commented 10 years ago

@23tux

  1. Yes, bgGeo tracks only in background. fg-tracking, use standard Cordova geolocation as per their docs.
  2. The Android version operates in a completely different fashion and is currently managed by a colleague. It does share the same Javascript file but it does HTTP in the native plugin. It does not execute your js-callback when a geolocation is recorded. The Android plugin is currently suitable for our client for which it was designed.
  3. It's unnecessary to add "background-modes: location" in XCode, since the plug is able to automatically add that to the Info.plist file.
christocracy commented 10 years ago

@23tux your question "how to determine when app comes to fg/bg" and how to start watchPosition are beyond the scope of my plugin.

@see http://cordova.apache.org/docs/en/3.3.0/cordova_geolocation_geolocation.md.html#Geolocation

http://cordova.apache.org/docs/en/3.3.0/cordova_events_events.md.html#Events

christocracy commented 10 years ago

@akshayakrsh Did you try adding:

bgGeo.configure({debug: true});

That enables debugging sounds for the life-cycle events. Enable that and go for a walk outside with your headphones on or keep your phone speakers near your ear.

christocracy commented 10 years ago

@23tux Once you get your cordova GeoLocation plugin included, do this in your deviceready handler:

navigator.geolocation.getCurrentPosition();

That will trigger the YES/NO dialog asking user for permission to see Location.

At that point, you should see log-file output from bgGeo as shown above. The key log-message is:

CDVBackgroundGeoLocation createStationaryRegion (42.288231,-87.952480)

That shows the creation of the stationary-region of radius #stationaryRadius, centred upon the lat/lng as shown. Walk out of that region and aggressive-tracking will be engaged.

christocracy commented 10 years ago

hey @23tux, @akshayakrsh I just tested toggling Airplane mode while bg-geo is running: bg-geo plugin just starts working where it left off.

akshayakrsh commented 10 years ago

@christocracy perfait. tres bien!

23tux commented 10 years ago

@christocracy Thank you for your effort, but I still can't get it to work. I only get this output in my XCode log:

2014-02-11 15:16:19.143 tracker[2550:60b] Multi-tasking -> Device: YES, App: YES
2014-02-11 15:16:19.201 tracker[2550:60b] Unlimited access to network resources
2014-02-11 15:16:19.567 tracker[2550:60b] [CDVTimer][splashscreen] 168.249011ms
2014-02-11 15:16:19.571 tracker[2550:60b] [CDVTimer][TotalPluginStartup] 173.048019ms
2014-02-11 15:16:19.613 tracker[2550:60b] active
2014-02-11 15:16:20.793 tracker[2550:60b] Resetting plugins due to page load.
2014-02-11 15:16:21.283 tracker[2550:60b] Finished load of: file:///var/mobile/Applications/49A5E640-BD77-46EA-A5E5-CCE19ACF6ED2/tracker.app/www/index.html
2014-02-11 15:16:21.581 tracker[2550:60b] THREAD WARNING: ['Geolocation'] took '36.718018' ms. Plugin should use a background thread.
2014-02-11 15:16:21.605 tracker[2550:60b] CDVBackgroundGeoLocation configure
2014-02-11 15:16:21.610 tracker[2550:60b]   - token: BackgroundGeoLocation_auth_token
2014-02-11 15:16:21.614 tracker[2550:60b]   - url: BackgroundGeoLocation_url
2014-02-11 15:16:21.619 tracker[2550:60b]   - distanceFilter: 50
2014-02-11 15:16:21.623 tracker[2550:60b]   - stationaryRadius: 50
2014-02-11 15:16:21.627 tracker[2550:60b]   - locationTimeout: 60
2014-02-11 15:16:21.631 tracker[2550:60b]   - desiredAccuracy: 100
2014-02-11 15:16:21.636 tracker[2550:60b]   - debug: 1
2014-02-11 15:16:21.640 tracker[2550:60b] THREAD WARNING: ['BackgroundGeoLocation'] took '35.398926' ms. Plugin should use a background thread.
2014-02-11 15:16:21.645 tracker[2550:60b] - CDVBackgroundGeoLocation start (background? 0)
2014-02-11 15:16:21.811 tracker[2550:60b] getCurrentPosition success: [object Object]
2014-02-11 15:16:21.852 tracker[2550:60b] THREAD WARNING: ['Console'] took '41.084961' ms. Plugin should use a background thread.

I first searched for the Resetting plugins due to page load. line, because this seems strange. I found this answer http://stackoverflow.com/questions/19671249/phonegap-cordova-3-1-resetting-plugins-due-to-page-load that this isn't really a bug.

As you can see, some of the CDVBackgroundGeoLocation are shown, but not the one you mentioned. Here is my index.html:

<!doctype html>
<html>
    <head>
        <title>tracker</title>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="lib/jquery-1.9.1.min.js"></script>
    </head>
    <body>
      <script type="text/javascript" charset="utf-8">
      document.addEventListener("deviceready", function () {
        // to ask the first time for the current location
        navigator.geolocation.getCurrentPosition(function(event) {
          console.log("getCurrentPosition success: " + event);
        });

        var bgGeo = window.plugins.backgroundGeoLocation;
        var callback = function(location) {
          console.log(location);
          $.ajax({
            url: 'http://www.my-server.com/json.php',
            type: 'POST',
            data: JSON.stringify({lat: location.latitude, lng: location.longitude}),
            dataType: "json",
            success: function(data) {
              console.log("SUCCESS: " + data);
              bgGeo.finish();
            },
            error: function(data) {
              console.log("ERROR: " + data);
              bgGeo.finish();
            }
          });
        };

        var failFn = function(event) {
          console.log("FAILED BACKGROUND TRACKING: " + event);
        }

        bgGeo.configure(callback, failFn, {
          stationaryRadius: 50,  // meters
          distanceFilter: 50,    // meters
          debug: true            // enables sounds for bg-tracking events for debugging.
        });

        // Enable background geolocation
        bgGeo.start();
      });
    </script>
    </body>
</html>

The whole thing is build with cordova 3.3.0. Hope you can help me, and sorry for being so annoying ;)

UPDATE:

I just found out, that when sending the app into background mode, there are more logs. I assumed, that they has to be at startup time.

When sending the app in background, I get this logs:

2014-02-11 15:46:38.798 tracker[2612:60b] - CDVBackgroundGeoLocation start (background? 0)
2014-02-11 15:47:20.162 tracker[2612:60b] - CDVBackgroundGeoLocation suspend (enabled? 1)
2014-02-11 15:47:20.171 tracker[2612:60b] - CDVBackgroundGeoLocation setPace 0, stationaryRegion? 0

Then, nothing happens. When I try to simulate the position with XCode, I get this logs:

2014-02-11 15:48:44.098 atalogics Kurier App[2612:60b] - CDVBackgroundGeoLocation didUpdateLocations (isMoving: 0)
2014-02-11 15:48:44.113 atalogics Kurier App[2612:60b] - Acquiring stationary location, accuracy: 5.000000
2014-02-11 15:48:44.128 tracker[2612:60b] - CDVBackgroundGeoLocation createStationaryRegion (51.509980,-0.133700)
2014-02-11 15:48:44.647 tracker[2612:310f]  51.509980,-0.133700

But my callback isn't fired. When bringing the app back to foreground, then my callback is fired. I also tried to go around in my neighborhood, but the same here, no callback is fired in the background.

And sometimes, when bringing the app to back- or foreground, I get this in my logs

locationManager::didFailWithError (null)
christocracy commented 10 years ago

@23tux Skype me. christocracy.

ggollapinni commented 10 years ago

your latest for ios is in master or ios branch?. We are testing on ios from the master branch, the plugin starts only when the app goes to back ground, but it kept tracking when the app came to foreground. The bgGeo.stop() didn't make the service stop, still it was tracking when the app was in the foreground. Testing with ios simulator 7.1.

christocracy commented 10 years ago

ios branch.

The plugin is designed to only track in the background. That's why its named "cordova-background-geolocation". It's up to you to track in foreground using standard Cordova Location api.

Are you executing #stop while app is in foreground?

On Thu, Mar 27, 2014 at 3:40 PM, ggollapinni notifications@github.comwrote:

your latest for ios is in master or ios branch?. We are testing on ios from the master branch, the plugin starts only when the app goes to back ground, but it kept tracking when the app came to foreground. The bgGeo.stop() didn't make the service stop, still it was tracking when the app was in the foreground. Testing with ios simulator 7.1.

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-38851024 .

Chris Scott Transistor Software http://www.transistorsoft.com

christocracy commented 10 years ago

Please open a new issue, this one is closed.

ggollapinni commented 10 years ago

I am aware of how it supposed to work, but it was tracking even when the app was in the foreground. Yes I have a button ‘stop tracking’ and I am calling bgGeo.stop on click, from java script.

Is the ios latest is on master or ios branch?

christocracy commented 10 years ago

send me the ios logs showing this.

Snet form my iPhone

On Mar 27, 2014, at 6:56 PM, ggollapinni notifications@github.com wrote:

I am aware of how it supposed to work, but it was tracking even when the app was in the forground. Yes I have a button ‘stop tracking’ and I am calling bgGeo.stop on click, from java script.

From: Chris Scott [mailto:notifications@github.com] Sent: Thursday, March 27, 2014 4:15 PM To: christocracy/cordova-plugin-background-geolocation Cc: ggollapinni Subject: Re: [cordova-plugin-background-geolocation] iOS: 'CDVLocation.h' file not found (#4)

ios branch.

The plugin is designed to only track in the background. That's why its named "cordova-background-geolocation". It's up to you to track in foreground using standard Cordova Location api.

Are you executing #stop while app is in foreground?

On Thu, Mar 27, 2014 at 3:40 PM, ggollapinni <notifications@github.com mailto:notifications@github.com >wrote:

your latest for ios is in master or ios branch?. We are testing on ios from the master branch, the plugin starts only when the app goes to back ground, but it kept tracking when the app came to foreground. The bgGeo.stop() didn't make the service stop, still it was tracking when the app was in the foreground. Testing with ios simulator 7.1.

Reply to this email directly or view it on GitHubhttps://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-38851024 .

Chris Scott Transistor Software http://www.transistorsoft.com

— Reply to this email directly or view it on GitHub https://github.com/christocracy/cordova-plugin-background-geolocation/issues/4#issuecomment-38854924 . https://github.com/notifications/beacon/3238956__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxMTU3MDUxNywiZGF0YSI6eyJpZCI6MjUzMDc0NzZ9fQ==--d395d0d31e232bfae5a3db4642e5de852625cab9.gif — Reply to this email directly or view it on GitHub.