2016-02-18 88 views
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]); 
} 

回答

0

好吧我刚刚从Github下载了我自己的最小项目,并用iPhone 5S模拟器尝试过。它有效。之前我只用6S试过它,但没有奏效。现在将尝试在设备6(S),并希望在那里工作以及..

但也许会帮助某人在不久的将来:)