3

My CLLocationManager starts when the user first enters the app. I am initializing it like this:

self.locationManager = [[CLLocationManager alloc] init];
            self.locationManager.delegate = self;
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            self.locationManager.distanceFilter = kDistanceFilter;
            self.locationManager.headingFilter = kHeadingFilter;

And I am using geofencing.

I have defined in my .plist the required background modes.

If I test the app in the simulator using a gpx file, it works fine. So far, so good.

However, I read in these two links:

Start Location Manager in iOS 7 from background task

Background Location Services not working in iOS 7

That in iOS7, when the location does not change for a couple of minutes then the CLLocation goes to sleep.

My question is that:

I do not call didUpdateLocation at all, I only want the didEnterRegion, or didExitRegion. Theoretically, will it work , even the app is killed or user Location has not changed in the last hour and then decides to move?

Community
  • 1
  • 1
ghostrider
  • 5,131
  • 14
  • 72
  • 120
  • 1
    If the app is killed explicitly by the user, under iOS7, you will not get ANY updates. There is nothing that can be done about this. – danielbeard Jan 14 '14 at 16:41
  • Take a look into this SO post: http://stackoverflow.com/questions/18639976/significant-blocation-change-event-in-ios7-background-service-call – Sviatoslav Yakymiv Jan 14 '14 at 16:45
  • how @danielbeard already said "If the app is killed explicitly by the user, under iOS7, you will not get ANY updates"!!! You can check this behavior with Apple's Location based reminders: if you kill the "Remainders" App - you will not be notified ever about location entry/exit! – TonyMkenu Jan 15 '14 at 10:37
  • ..and about "CLLocation goes to sleep" if the location does not change - it is the normal behavior, don't you think so? :) – TonyMkenu Jan 15 '14 at 10:41

1 Answers1

2

There are a few elements in your questions:

1- In order not to rehash what is in a previous answer, I would first look at my answer at this link. It will help you resolve around the core location updates stopping if the user stops moving and how you can modify that behaviour: iOS7 Core Location not updating

2- If the user kills an app in iOS7 (by flicking it up in the app switcher), the app will not restart and as such neither your location updates nor region monitoring will restart after the phone is restarted. On the other hand, if the app is killed because of memory pressures, iOS will restart the app and relaunch your location updates and region monitoring in the background. Also, if you reboot the phone, region monitoring will restart automatically. You obviously must have the background mode enabled.

3- Now you are talking about regions in your questions so I am assuming you have implemented CLCircularRegion. If not, that should be the first step and then "startMonitoringForRegion". In your case, even if the user has stopped moving for a while and then started moving, the app will be awaken/delegate called when the app enters or exit a region.

4- Make sure to use locationManager: didDetermineState: forRegion: as well. This will allow the app to determine if it is inside or outside of the region at start. This is useful when you think of an app being launched and no region crossing has happened but it is important to know whether the user is inside or outside of the region.

Hope this helps

Community
  • 1
  • 1
Khaled Barazi
  • 8,681
  • 6
  • 42
  • 62
  • Thanks for the answer. I have implemented most of these. Just a question on 2 - when user kills the app, the region monitoring stops working? So even if he enters the region/leaves it, if the app is killed by the user, then the delegate is not called, right? – ghostrider Jan 14 '14 at 19:46
  • That is correct. This is to protect the user. Apple wants always the user to maintain control. So if the user says s/he does not want the app running in the background (i.e, the user kills the app) then it is killed and not relaunched (and its region monitoring is not relaunched). – Khaled Barazi Jan 15 '14 at 02:45