我正在使用 iPhone 上的 LocationManager 开发一个位置跟踪应用程序。以下是我的问题。如果用户点击iphone上的Home键,意味着应用程序切换到后端,位置管理器的线程是否仍然有效?位置管理器会更新当前位置吗?以下是示例代码。
CLLocationManager *_locationManager;
- (void)startStandardUpdates {
if (nil == locationManager) {
locationManager = [[CLLocationManager alloc] init];
}
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Set a movement threshold for new events.
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
//Will the thread still work even the application is switched to background?
[locationManager startUpdatingLocation];
CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
PAWAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.currentLocation = currentLocation;
}
}