0
我有startMonitoringSignificantLocationChanges的問題。如果我將此方法稱爲我的locationManager,則方法只會被調用一次。現在,如果我在模擬器中啓動Drive(如描述here - Debug - > Location - > Freeway Drive),則不會再調用它。蘋果公司規定,應該每隔500米或甚至每5至15分鐘調用一次。我等待,等待,並沒有成功。startMonitoringSignificantLocationChanges代表只調用一次
這是小代碼,我也做了Github minimal example。當然也不會調用錯誤方法。它沒有在真正的汽車上進行測試,因爲我認爲它應該先在模擬器中運行。我在這裏錯過了什麼?
- (void)viewDidLoad {
[super viewDidLoad];
if(self.locationManager == nil){
self.locationManager = [[CLLocationManager alloc] init];
}
// Set the delegate
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startMonitoringSignificantLocationChanges];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
CLLocation *currentLoc = [locations lastObject];
NSLog(@"New Location: %f/%f, Locations: %lu", currentLoc.coordinate.latitude, currentLoc.coordinate.longitude,(unsigned long)[locations count]);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"Loc Error: %@", [error userInfo]);
}