Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS 7中请求位置_Ios_Swift_Cllocationmanager - Fatal编程技术网

如何在iOS 7中请求位置

如何在iOS 7中请求位置,ios,swift,cllocationmanager,Ios,Swift,Cllocationmanager,我想在iOS 7+中请求位置。我可以在iOS 8+中通过以下方式实现这一点: locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestWhenInUseAuthorization() locationManager.requestLocation() 但在iOS 7中,我不能使用以下两行: locationManager

我想在iOS 7+中请求位置。我可以在iOS 8+中通过以下方式实现这一点:

locationManager.delegate = self 
locationManager.desiredAccuracy = kCLLocationAccuracyBest 
locationManager.requestWhenInUseAuthorization() 
locationManager.requestLocation()
但在iOS 7中,我不能使用以下两行:

locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()


任何帮助都将不胜感激。谢谢。

创建
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
}

嘿正如我所说,我可以在iOS 8+中请求位置,但我不知道如何在iOS 7中请求位置。