【问题标题】:How to detect if a user says no to use my default location? [duplicate]如何检测用户是否拒绝使用我的默认位置? [复制]
【发布时间】:2013-01-29 10:06:16
【问题描述】:

可能重复:
Determining if user has denied CoreLocation permission

我将如何检测用户是否拒绝在 iOS 应用中“使用我的默认位置”?

我想根据他们的选择为他们提供不同的视图控制器。

谢谢

【问题讨论】:

    标签: iphone ios objective-c core-location


    【解决方案1】:

    为此,您需要实现以下委托方法:

    - (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
    {
        if([error code]== kCLErrorDenied)
            self.locationDenied = YES;
    
            switch ([error code]) {
            // "Don't Allow" on two successive app launches is the same as saying "never allow". The user
            // can reset this for all apps by going to Settings > General > Reset > Reset Location Warnings.
            case kCLErrorDenied:
                [appDelegate showAllowGPSLocationView];
            default:
                break;
        }
    
        self.locationDefined = NO;
    }
    

    您可以在 AppDelegate 中创建方法“showAllowGPSLocationView”。并向用户显示,您需要访问 GPS 位置。

    希望它能解决您的问题。

    编码愉快!

    【讨论】:

      【解决方案2】:
      -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
      
          if (status == kCLAuthorizationStatusDenied) {
              // denied
          }
          else if (status == kCLAuthorizationStatusAuthorized) {
              // allowed
          }
      }
      

      实现CLLocationManagerDelegate委托 有关详细说明,请参阅here。为我工作。希望对您有所帮助..

      【讨论】:

        【解决方案3】:

        我为此创建了一个函数,它通过两种方式解决了这个问题:首先检查是否启用了位置服务(设备上的第一个位置设置),然后检查用户是否授权了您的应用。

        - (bool)locationAvailable
        {
            if (!([CLLocationManager locationServicesEnabled]) || ( [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied))
                return FALSE;
            else
                return TRUE;
        }
        

        【讨论】:

          【解决方案4】:

          您可以尝试如下:

           #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_2
              if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized))  
           #else 
              if ([CLLocationManager locationServicesEnabled])    
           #endif
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-04-18
            • 1970-01-01
            • 1970-01-01
            • 2019-05-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多