Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 如何先申请GPS许可';使用';时;,然后是';总是';?(2个步骤)_Ios_Geolocation - Fatal编程技术网

Ios 如何先申请GPS许可';使用';时;,然后是';总是';?(2个步骤)

Ios 如何先申请GPS许可';使用';时;,然后是';总是';?(2个步骤),ios,geolocation,Ios,Geolocation,我正在设计一个可以与签入一起工作的应用程序 使用应用程序时的GPS权限是必须的。但是有一个可选功能用于使用地理围栏进行自动登记,它需要“始终”gps许可 首先,我想请求常规的“使用时”权限。然后,只有当用户需要自动签入时,才请求“始终”权限 可能吗? -->首先将这三个键添加到info.plist文件中,或者您可以根据需要添加第1键和第2键或第1键和第3键 -->在“myclass.h”中,将委托设置为“CLLocationManagerDelegate”,它将在首次使用时要求您提供GPS,并将

我正在设计一个可以与签入一起工作的应用程序

使用应用程序时的GPS权限是必须的。但是有一个可选功能用于使用地理围栏进行自动登记,它需要“始终”gps许可

首先,我想请求常规的“使用时”权限。然后,只有当用户需要自动签入时,才请求“始终”权限

可能吗?

-->首先将这三个键添加到info.plist文件中,或者您可以根据需要添加第1键和第2键或第1键和第3键

-->在“myclass.h”中,将委托设置为“CLLocationManagerDelegate”,它将在首次使用时要求您提供GPS,并将下面的代码添加到“myclass.m”文件中

}

--注意:如果您希望始终使用GPS权限,则在权限中使用时无需请求

-->如果您同时添加这两个权限,那么您将在设备设置应用程序中获得此类选项,用户还可以设置何时使用哪种权限。一个权限不会同时显示在设备设置中

设备设置-->我的应用-->允许我的应用访问(选择位置)-->位置访问权限

CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    [locationManager requestWhenInUseAuthorization];   //For while use the app
[locationManager requestAlwaysAuthorization]; // For always usage of GPS 
[locationManager startUpdatingLocation];


NSLog(@"%@",[NSString stringWithFormat:@"%f",locationManager.location.coordinate.latitude] );
NSLog(@"%@",[NSString stringWithFormat:@"%f",locationManager.location.coordinate.longitude] );

  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);