Turning off the GPS updates when user hits the home button on iPhone
I have an application with four tabs. Two of the tabs use location updates and other two don't require GPS. I use following code to turn off the location updates when the view is about to disappear
- (void)viewWillDisappear:(BOOL)animated { [self.locationManager stopUpdatingLocation]; }
This seems to work when I change tabs. The puzzle is that when user hits the home button while in the tabs which do not require location information then GPS is turned off. However if the user hits the home button while in one of the tabs that is using location up开发者_如何学编程dates then the GPS is left turn on. I think it is because "viewWillDisappear" is never called when the user hits the home button.. Am I right in that assumption, any suggestion on how to fix this problem.
Soofi
Add the "UIBackgroundModes" key to your -Info.plist but don't specify any values, that should ensure location services are not used in the background.
well, unless you've specifically set up the app to have background services for gps, it won't continue running, and I'm guessing you have not done so, otherwise, you wouldn't be asking how to stop it...however, for completeness, just in case you really do want that, I think you want the applicationDidEnterBackground method
精彩评论