有一个位置更新的代表确实失败了
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
有几种错误:kCLErrorDenied
kCLErrorNetwork
在上面的委托方法中添加代码来处理它们,而不是更新位置,也许是UIAlertView
为了告诉用户。
就个人而言,我会调用 [locationManager stopUpdatingLocation];
任何错误,然后根据失败的原因使用错误消息重新启动它。
也重新背景,检查您的 appDelegate 中的代码:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[self saveContext];
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
// Stop normal location updates and start significant location change updates for battery efficiency.
[self.locationHandler.locationManager stopUpdatingLocation];
[self.locationHandler.locationManager startMonitoringSignificantLocationChanges];
}
else {
NSLog(@"Significant location change monitoring is not available.");
}
}
最后回复:测试。您可以通过更改模拟器中的位置移动来模拟一些位置错误。例如,从跑步到开车会导致错误。从运行到单个特定的自定义位置会导致错误。它们都应该出现在上面 locationManager 的委托方法中。