2016-05-26 42 views
-1

我想請求在iOS 7+中的位置。我可以用這個iOS中實現這一8+:如何在iOS 7中請求位置

locationManager.delegate = self 
locationManager.desiredAccuracy = kCLLocationAccuracyBest 
locationManager.requestWhenInUseAuthorization() 
locationManager.requestLocation() 

但在iOS的7,我不能使用這兩個行:

locationManager.requestWhenInUseAuthorization() 
locationManager.requestLocation() 

enter image description here

任何幫助,將不勝感激。謝謝。

+0

嘿!檢查這篇文章出 http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/ –

+0

正如我所說,我可以要求在iOS 8+的位置,但我不知道如何在iOS 7中請求位置。 – Khuong

回答

-2

創建一個CLLocationManager的實例(最好在您的AppDelegate中)。堅持引用它。

-(void)startLocationService{ 

    self.locationManager = [[CLLocationManager alloc] init]; 
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    _locationManager.delegate = self; 
    [_locationManager startUpdatingLocation]; 
} 

現在執行委託方法如下。

-(void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
        fromLocation:(CLLocation *)oldLocation 
{ 
//Your logic to process the location 
}