【问题标题】:Do not show alert each time when startUpdatelocation每次 startUpdatelocation 时不显示警报
【发布时间】:2016-07-10 06:10:05
【问题描述】:

我正在开发需要获取位置的位置应用程序。当我打开特定的 ViewController 并且位置已关闭时,它会发出警报,显示该位置的开关很好。但问题是一旦我说取消并下次致电 [locationManager startUpdatingLocation]; 它不会向我显示打开位置的警报。

  - (void)getCurrentLocation {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        locationManager.distanceFilter = kCLDistanceFilterNone;

        if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {

            [locationManager requestAlwaysAuthorization];
        }

        [locationManager startUpdatingLocation];

    }

注意 - 我在 plist 中做了更改 NSLocationAlwaysUsageDescription 设置为 XYZ 应用想要使用 你现在的位置

【问题讨论】:

    标签: ios iphone cllocationmanager


    【解决方案1】:

    遗憾的是,这是设计使然。这样应用程序开发人员就不能用无休止的请求来骚扰用户。

    您需要做的是检查[CLLocationManager authorizationStatus],如果是kCLAuthorizationStatusDenied,则显示一条消息,用户需要进入他们的设置应用程序并为您的应用程序启用位置。

    您还应该处理其他授权状态。查看CLLocationManager Documentation - CLAuthorizationStatus中的列表

    【讨论】:

      【解决方案2】:

      在 startUpdatingLocation 之前检查状态。即

                if([CLLocationManager locationServicesEnabled])
                   {
                      if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
                          NSLog(@"Add your alert here");
                      }
                      else
                      {
                          [locationManager startUpdatingLocation];
                      }
                  }
                  else
                  {
                      NSLog(@"Add your alert here");
                  }
      

      【讨论】:

      • 谢谢你 Minkle 它会增加大卫的观点。 +1 帮助。
      猜你喜欢
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 2016-05-25
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      相关资源
      最近更新 更多