【问题标题】:iOS Unreliable Location Permission AlertiOS 不可靠位置权限警报
【发布时间】:2017-07-12 04:20:48
【问题描述】:

在我们的应用中,我们要求在一个用于显示地图的视图上获得位置许可 (WhenInUse)。

如果用户选择禁用设备定位服务(即在设备设置中全局禁用)然后在应用中打开我们的视图,将显示定位权限弹出窗口。重复冲洗几次(重新打开服务、继续应用、离开应用、关闭服务等),几次后位置权限警报将停止显示。

有人知道这是否是 iOS 中的错误(发生在 iOS 10 上)?

我们可以使用自己的警报来显示何时

CLLocationManager locationServicesEnabled = NO

但由于我们无法控制是否/何时弹出 iOS 位置警报,因此有时它们会同时显示,这是不好的用户体验。

该问题的任何已知解决方案?如果这是 iOS 中的错误,我必须向我们的 QA 和经理解释。

编辑:

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

【问题讨论】:

    标签: ios cocoa-touch permissions geolocation alert


    【解决方案1】:

    如果我没记错的话,iOS 对话框只有在authorizationStatusundetermined 时才会发出。 如果状态为denied(当只有特定应用被拒绝或整个定位服务被禁用时),您需要发出自己的对话框,其中包含指向设置的深层链接

    【讨论】:

      【解决方案2】:

      我不认为这是一个错误,这是不同的 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];
          }
      }
      

      因此,如果用户从设置中禁用定位服务,警报视图可以重定向到设置页面。

      这样就不会显示多个 AlertView。这仅取决于您希望如何处理每种情况,例如:

      • 在“设置”中启用了定位服务,但此应用的权限被拒绝
      • 在设置中启用定位服务并获得授权
      • 在“设置”中禁用了定位服务

      确保您处理每个案例并进行测试。

      不知道我是否准确回答了您的问题,希望对您的实施有所帮助。

      【讨论】:

      • 我的方法以类似的方式实现,检查 locationServicesEnabled 但它不起作用。您可以看到我在上面添加的代码。尽管我的方法应该处理所有情况并确保 iOS 位置权限警报仅在 kCLAuthorizationStatusNotDetermined 的情况下显示,但当我尝试仅显示我的自定义警报时它也会出现。而且我不会在其他任何地方调用 requestWhenInUseAuthorization。
      • 实际上,我在 Google 地图应用上观察到了同样不稳定的权限警报行为。毕竟这似乎是预期的 iO​​S 默认行为或 iOS 中的错误。
      • @BadmintonCat 这很奇怪,您的方法似乎可以处理所有情况。但我仍然认为这不是 iOS 错误。我发现这篇文章可能会有所帮助,但我确定你已经检查过了stackoverflow.com/questions/39695201/…
      猜你喜欢
      • 2018-12-03
      • 2019-04-18
      • 2017-08-24
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-18
      相关资源
      最近更新 更多