简体   繁体   English

iOS不可靠的位置权限警报

[英]iOS Unreliable Location Permission Alert

In our app we ask for location permission (WhenInUse) on one view that is used to display a map. 在我们的应用中,我们要求用于显示地图的一个视图上的位置许可(WhenInUse)。

If the user choses to disable device location service (ie globally disabled in device settings) and then opens our view in the app, the location permission popup will show. 如果用户选择禁用设备位置服务(即在设备设置中全局禁用),然后在应用程序中打开我们的视图,则将显示位置权限弹出窗口。 Rinse repeat a few times (turn service back on, go on app, leave app, turn service off, etc.) and after a few times the location permission alert will stop showing. 重复冲洗几次(重新打开服务,打开应用程序,离开应用程序,关闭服务等),然后重复几次,位置权限警报将停止显示。

Anyone know if this is a bug in iOS (happens on iOS 10)? 有人知道这是否是iOS中的错误(发生在iOS 10上)吗?

We could use our own alert that shows when 我们可以使用自己的警报来显示何时

CLLocationManager locationServicesEnabled = NO

but since we have no control about if/when the iOS location alert pops up, it sometimes happens that they both would show at the same time which is bad UX. 但由于我们无法控制是否/何时弹出iOS位置警报,因此有时会同时出现这两种情况,这是错误的UX。

Any known solution to the problem? 任何已知的解决方案? I have to explain to our QA and manager if this is a bug in iOS. 如果这是iOS中的错误,我必须向我们的质量检查和经理解释。

EDIT: 编辑:

- (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;
    }
}

I don't think this is a bug, this is different AlertView. 我不认为这是一个错误,这与AlertView不同。

If the user accept the location permission once, it's saved, it won't ask him again. 如果用户一次接受位置许可,则将其保存,不会再询问他。 But if the location service is disabled, this is a different case scenario. 但是,如果禁用了位置服务,则情况将有所不同。

You can implement it this way : 您可以这样实现:

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];
    }
}

So if the user disables the location service from the Settings, the alert view can make a redirection to the Settings page. 因此,如果用户从“设置”中禁用了定位服务,则警报视图可以重定向到“设置”页面。

This way multiple AlertViews won't show up. 这样就不会显示多个AlertViews。 It just depends how you want to handle every case scenario like : 这仅取决于您要如何处理每种情况,例如:

  • Location service enabled in Settings but permission denied for this App 在“设置”中启用了定位服务,但对此应用程序的权限被拒绝
  • Location service enabled in Settings and authorized permission 在设置和授权权限中启用了定位服务
  • Location service disabled in Settings 在设置中禁用了定位服务

Make sure you handle every case, and test it out. 确保处理好每种情况,然后进行测试。

I don't know if I answered your question precisely, I hope it will help for your implementation. 我不知道是否能准确回答您的问题,希望对您的实施有所帮助。

If I remember correctly, the iOS dialog is only issued when authorizationStatus is undetermined . 如果我没记错的话,只有在authorizationStatus undetermined时才发出iOS对话框。 if the status is denied (when only the specific app is denied or the entire location service is disabled) you need to issue your own dialog with a deep link to settings 如果状态被denied (当仅特定应用被拒绝或整个位置服务被禁用时),您需要发出自己的对话框,其中包含指向设置的深层链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM