2015-09-17 34 views
1

位置管理器didUpdateLocations沒有被調用。位置管理器的delagate方法沒有被調用

self.locationManager = [[CLLocationManager alloc] init]; 

self.locationManager.delegate = self; 

[self.locationManager startUpdatingLocation]; 

for call back i am using this delegate method 

- (void)locationManager:(CLLocationManager)manager didUpdateLocations:(NSArray)locations 
{ 
    NSLog(@"%@", [locations lastObject]); 
} 
+0

您是否導入了位置的框架? –

回答

0

進口框架CoreLocation

self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) 
    { 
     [self.locationManager requestWhenInUseAuthorization]; 
    } 
    [self.locationManager startUpdatingLocation]; 

在iOS8上和較新的,你有權要求致電requestAlwaysAuthorization或requestWhenInUseAuthorization使用明確的定位服務的權限。

相關問題