Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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位置服务-应用程序在允许之前正在检查位置_Ios_Geolocation_Cllocationmanager_Clgeocoder - Fatal编程技术网

iOS位置服务-应用程序在允许之前正在检查位置

iOS位置服务-应用程序在允许之前正在检查位置,ios,geolocation,cllocationmanager,clgeocoder,Ios,Geolocation,Cllocationmanager,Clgeocoder,只是试图确定用户的位置。代码如下: self.locationManager = [[CLLocationManager alloc] init]; //self.locationManager.delegate = self; self.locationManager.distanceFilter = 80.0; [self.locationManager startUpdatingLocation]; self.geoCoder = [[CLGeocoder alloc] init]; [

只是试图确定用户的位置。代码如下:

self.locationManager = [[CLLocationManager alloc] init];
//self.locationManager.delegate = self;
self.locationManager.distanceFilter = 80.0;
[self.locationManager startUpdatingLocation];

self.geoCoder = [[CLGeocoder alloc] init];
[self.geoCoder reverseGeocodeLocation: self.locationManager.location completionHandler:

 ^(NSArray *placemarks, NSError *error) {

     CLPlacemark *placemark = [placemarks objectAtIndex:0];

     UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:@"Location" message:[NSString stringWithFormat:@"The app has determined that your country is: %@ (%@)", placemark.country, placemark.ISOcountryCode] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [alert show];


 }];
我第一次运行应用程序时,会弹出一个双重警报。locationAlert首先弹出,通知用户一个(空)国家,然后默认弹出,表示应用程序希望使用我的位置几乎同时弹出。如果单击“是”,下次运行应用程序时,我将获得用户正确国家/地区的单个弹出窗口


所以我的问题是,我如何首先获得访问用户位置的权限,然后运行此代码查找他们的位置,因为我未经允许查询了他们的位置,所以没有收到空响应?

反向地理位置代码正试图使用
locationManager
中的
location
属性,但在使用
CLLocationManager
委托方法之前该属性无效调用了
locationManager:didUpdateToLocation:fromLocation:

您应该有一个委托方法来处理位置更新