[英]iOS Unreliable Location Permission Alert
在我们的应用中,我们要求用于显示地图的一个视图上的位置许可(WhenInUse)。
如果用户选择禁用设备位置服务(即在设备设置中全局禁用),然后在应用程序中打开我们的视图,则将显示位置权限弹出窗口。 重复冲洗几次(重新打开服务,打开应用程序,离开应用程序,关闭服务等),然后重复几次,位置权限警报将停止显示。
有人知道这是否是iOS中的错误(发生在iOS 10上)吗?
我们可以使用自己的警报来显示何时
CLLocationManager locationServicesEnabled = NO
但由于我们无法控制是否/何时弹出iOS位置警报,因此有时会同时出现这两种情况,这是错误的UX。
任何已知的解决方案? 如果这是iOS中的错误,我必须向我们的质量检查和经理解释。
编辑:
- (BOOL)negotiateLocationServicePermission:(UIViewController *)context
{
/* Device location service is enabled. */
if ([CLLocationManager locationServicesEnabled])
{
/* App location service is already authorized. */
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse
|| [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways)
{
/* App location service is authorized. Start location updates ... */
[self startUpdatingLocation];
return YES;
}
else
{
/* App location service not yet authorized and status is not determined (aka: first time asking for permission). */
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
/* Request the location permission from the user. */
if ([self respondsToSelector:@selector(requestWhenInUseAuthorization)])
[self requestWhenInUseAuthorization]; /* iOS 8+ */
else
[self startUpdatingLocation]; /* iOS 7 */
return YES;
}
/* App location service not authorized and previously denied. */
else
{
/* App location service permission was denied before. */
// Show custom alert!
return NO;
}
}
}
/* Device location service is disabled. */
else
{
// Show custom alert!
return NO;
}
}
我不认为这是一个错误,这与AlertView不同。
如果用户一次接受位置许可,则将其保存,不会再询问他。 但是,如果禁用了位置服务,则情况将有所不同。
您可以这样实现:
if ([CLLocationManager locationServicesEnabled]){
NSLog(@"Location Services Enabled");
if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
alert = [[UIAlertView alloc] initWithTitle:@"App Permission Denied"
message:@"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
因此,如果用户从“设置”中禁用了定位服务,则警报视图可以重定向到“设置”页面。
这样就不会显示多个AlertViews。 这仅取决于您要如何处理每种情况,例如:
确保处理好每种情况,然后进行测试。
我不知道是否能准确回答您的问题,希望对您的实施有所帮助。
如果我没记错的话,只有在authorizationStatus
undetermined
时才发出iOS对话框。 如果状态被denied
(当仅特定应用被拒绝或整个位置服务被禁用时),您需要发出自己的对话框,其中包含指向设置的深层链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.