gpt4 book ai didi

ios - 如何首先为 'While Using' 请求 GPS 许可,然后为 'Always' 请求 GPS 许可? (2 个步骤)

转载 作者:行者123 更新时间:2023-11-29 12:18:12 27 4
gpt4 key购买 nike

我正在设计一款支持签到的应用。

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

我想首先请求常规的“使用时”权限。然后,仅当用户想要自动 checkin 时,请求“始终”权限。

这可能吗?

最佳答案

please add these 3 keys in your project's .plist file

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

-->在“myclass.h”中将委托(delegate)设置为“CLLocationManagerDelegate”,它会在第一次使用时要求您提供 GPS,并将以下代码写入“myclass.m”文件

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);

--注意:如果你想一直使用GPS权限那么在使用权限的时候不需要再询问。

enter image description here

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

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

关于ios - 如何首先为 'While Using' 请求 GPS 许可,然后为 'Always' 请求 GPS 许可? (2 个步骤),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31469573/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com