我想在iOS 7+中请求位置。我可以在iOS 8+中实现这一点:
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
但在iOS 7中,我无法使用这两行:
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
任何帮助将不胜感激。感谢。
答案 0 :(得分:-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
}