Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using your classes, this is what I would do.</p> <p>In your AppDelegate.m, when your app is in the foreground or background, I'd move the CLLocationManager to run in the foreground / background to match. The reason I'm doing this is because if the CLLocationManager is not moved to the background when the app is in the background, no location updates are sent to the CLLocationManager's callback</p> <pre><code>- (void)applicationDidEnterBackground:(UIApplication *) application { [[LocationController sharedInstance] stop]; [[LocationController sharedInstance] startMonitoringSignificantLocationChanges]; NSLog(@"entered background Mode"); } - (void)applicationDidBecomeActive:(UIApplication *) application { [[LocationController sharedInstance] stopMonitoringSignificantLocationChanges]; [[LocationController sharedInstance] start]; NSLog(@"application Did Become Active"); } </code></pre> <p>So lets say your app then moves to the background, and after awhile, iOS decides it's using too much memory and kills your app. </p> <p>A few minutes later, iOS then receives a location update, and respawns your app, letting it know it respawned due to a location service. You then need to re-start the background location service, as it will be the only chance your app has to do so. </p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) { [[LocationController sharedInstance] startMonitoringSignificantLocationChanges]; } return YES; } </code></pre> <p>Oh, and one last change, I'm not sure why in your <code>locationManager:didUpdateToLocation:fromLocation:</code> method you're stopping the location service, as when you do that no more updates come through. Just leave it running, then every time a location change comes through you can send that to the server. </p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if ( abs([newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) &lt; 30) { self.lastLocation = newLocation; [self updateLocation]; //sending location to server } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload