当用户拒绝访问位置服务时,您如何确定CLLocationManager? [英] How do you determine with CLLocationManager when a user denies access to location services?

查看:228
本文介绍了当用户拒绝访问位置服务时,您如何确定CLLocationManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CLLocationManager,我可以使用以下代码来确定我是否可以访问设备上的位置服务。这是所有应用程序的主设置,可以打开和关闭。

  if(self.locationManager.locationServicesEnabled){
[self.locationManager startUpdatingLocation];
}

但是用户可以拒绝对单个应用程序的访问,并且为了不执行要使用位置管理器的代码,我需要知道用户是否批准访问此特定应用的位置服务。我看到有一次有一个名为locationServicesApproved的属性,它显示它会指示用户是否批准在此应用中访问位置服务。但它在2008年被删除。



来源: http://trailsinthesand.com/apple-removes-notifications-from-iphone-sdk-beta-4/



似乎无法确定用户是否批准了对位置服务的访问,但似乎是SDK中的一个大漏洞。



这是SDK中的其他功能?我能做些什么来确定用户是否已批准访问当前应用程序的位置服务?

解决方案

我解答了我自己的问题在上面的问题的评论。



答案(从上面的评论复制):



看起来您必须等待locationManager:didFailWithError:被调用,并且错误代码将指向CLError.h中的值。值为kCLErrorLocationUnknown,kCLErrorDenied,kCLErrorNetwork和kCLErrorHeadingFailure。看起来第二个值是我应该检查用户是否拒绝对位置服务的访问。


With CLLocationManager I can use the following code to determine if I can access location services on the device. This is the master setting for all apps and can be turned on and off.

if (self.locationManager.locationServicesEnabled) {
    [self.locationManager startUpdatingLocation];
}

But a user can deny access to an individual app and in order to not execute the code to use the location manager I need to know if the user approved access to location services for this specific app. I saw that at one point there was a property called locationServicesApproved which appears it would indicate if the user approved access to location services in this app. But it was removed in 2008.

Source: http://trailsinthesand.com/apple-removes-notifications-from-iphone-sdk-beta-4/

It appears that there is no way to determine if the user approved access to location services but that seems to be a big hole in the SDK.

Is this feature in the SDK elsewhere? What can I do to determine if the user has approved access to location services for the current app?

解决方案

I answered my own question in the comment to the question above.

The answer (copied from the comment above):

It appears that you must wait for locationManager:didFailWithError: to be called and the error code will point to values in CLError.h. Values are kCLErrorLocationUnknown, kCLErrorDenied, kCLErrorNetwork, and kCLErrorHeadingFailure. It appears that the second value is what I should check to see if the user denied access to location services.

这篇关于当用户拒绝访问位置服务时,您如何确定CLLocationManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆