更改位置服务中的选项
Change the options in location services
在定位服务中,我的应用程序有三个选项:从不、使用时和始终。是否有可能更改这些选项,例如删除 While Using
选项?
编辑 1:
- (void)checkAuth {
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.manager requestAlwaysAuthorization];
} else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
[[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Setting", nil] show];
}
} else {
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.manager startUpdatingLocation];
[self.manager stopUpdatingLocation];
} else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized) {
[[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Setting", nil] show];
}
}
}
这是我用来要求授权的代码。
您应该只有您向用户请求的选项(除了 never,它将始终存在,因此他们可以选择禁用定位服务)。
如果出现 While Using
,这可能意味着您在代码中的某处使用了 [self.locationManager requestWhenInUseAuthorization]
。
你应该使用 [self.locationManager requestAlwaysAuthorization]
编辑:
万一您在开发时不小心请求了两个位置权限,您可能想要完全删除该应用程序,然后 运行 它再次只请求 requestAlwaysAuthorization
,如上所示。这将删除现有权限并重新提示用户。
Is there any possibility of changing these options like removing the
While Using option?
删除 SDK 选项? -> 不
处理吗? -> 是的
基本上,如果您想检查定位服务的当前状态,您可以像检查状态一样使用:
[CLLocationManager authorizationStatus]
根据苹果文档,它应该 return:
typedef enum {
kCLAuthorizationStatusNotDetermined = 0,
kCLAuthorizationStatusRestricted,
kCLAuthorizationStatusDenied,
kCLAuthorizationStatusAuthorized,
kCLAuthorizationStatusAuthorizedAlways = kCLAuthorizationStatusAuthorized,
kCLAuthorizationStatusAuthorizedWhenInUse
} CLAuthorizationStatus;
从那时起,我认为您已具备处理不同情况所需的一切。如果您想以相同的方式处理 Always 和 WhenInUse,只需在相同的 if.
中使用 OR 条件进行测试
如果需要,请在此处提供更多帮助:
我自己找的。在info.plist中,当您想要请求位置服务授权时,需要一些选项。
<key>NSLocationAlwaysUsageDescription</key> // 'Always' authorization
<string>Some message</string>
<key>NSLocationWhenInUseUsageDescription</key> // 'While in use' authorization
<string>Some message</string>
如果不需要,请删除其中的任何一个。
在定位服务中,我的应用程序有三个选项:从不、使用时和始终。是否有可能更改这些选项,例如删除 While Using
选项?
编辑 1:
- (void)checkAuth {
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.manager requestAlwaysAuthorization];
} else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
[[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Setting", nil] show];
}
} else {
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
[self.manager startUpdatingLocation];
[self.manager stopUpdatingLocation];
} else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized) {
[[[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Setting", nil] show];
}
}
}
这是我用来要求授权的代码。
您应该只有您向用户请求的选项(除了 never,它将始终存在,因此他们可以选择禁用定位服务)。
如果出现 While Using
,这可能意味着您在代码中的某处使用了 [self.locationManager requestWhenInUseAuthorization]
。
你应该使用 [self.locationManager requestAlwaysAuthorization]
编辑:
万一您在开发时不小心请求了两个位置权限,您可能想要完全删除该应用程序,然后 运行 它再次只请求 requestAlwaysAuthorization
,如上所示。这将删除现有权限并重新提示用户。
Is there any possibility of changing these options like removing the While Using option?
删除 SDK 选项? -> 不 处理吗? -> 是的
基本上,如果您想检查定位服务的当前状态,您可以像检查状态一样使用:
[CLLocationManager authorizationStatus]
根据苹果文档,它应该 return:
typedef enum {
kCLAuthorizationStatusNotDetermined = 0,
kCLAuthorizationStatusRestricted,
kCLAuthorizationStatusDenied,
kCLAuthorizationStatusAuthorized,
kCLAuthorizationStatusAuthorizedAlways = kCLAuthorizationStatusAuthorized,
kCLAuthorizationStatusAuthorizedWhenInUse
} CLAuthorizationStatus;
从那时起,我认为您已具备处理不同情况所需的一切。如果您想以相同的方式处理 Always 和 WhenInUse,只需在相同的 if.
中使用 OR 条件进行测试如果需要,请在此处提供更多帮助:
我自己找的。在info.plist中,当您想要请求位置服务授权时,需要一些选项。
<key>NSLocationAlwaysUsageDescription</key> // 'Always' authorization
<string>Some message</string>
<key>NSLocationWhenInUseUsageDescription</key> // 'While in use' authorization
<string>Some message</string>
如果不需要,请删除其中的任何一个。