2016-02-18 47 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),並希望在那裏工作以及..

但也許會幫助某人在不久的將來:)