why CLLocationManager always returns true?

北战南征 提交于 2019-12-13 00:33:18

问题


I am using [CLLocationManager locationServicesEnabled] function to get the status whether location service is enabled or not. I kept code in viewDidLoad method.

if(![CLLocationManager locationServicesEnabled])
{
    NSLog(@"No");
}
else
{
    NSLog(@"Yes");
}

When I am running this app first time it returns Yes. Why? It should return me No. This is the case when I did not select "Allow" or "Don't allow" options. Means I neither allow nor don't allow but in viewDidLoad I got Yes.

Now I select "Don't allow" and again load the same viewController. At this time at least it should return me No, but still I got Yes. Why?

So much of confusion with CLLocationManager.

Any ideas?


回答1:


locationServicesEnabled returns whether location service is enabled on settings.. If it is enabled in settings, this function returns YES all the time..

from documentation

locationServicesEnabled

Returns a Boolean value indicating whether location services are enabled on the device.

Discussion

The user can enable or disable location services from the Settings application by toggling the Location Services switch in General.

You should check the return value of this method before starting location updates to determine whether the user has location services enabled for the current device. If this method returns NO and you start location updates anyway, the Core Location framework prompts the user to confirm whether location services should be reenabled.

Whether or not user allowed/rejected app permission (in the alertview) doesn't affect the return value of this method.

If you want to know whether user has given application permission to access location, you can use authorizationStatus.



来源:https://stackoverflow.com/questions/13969368/why-cllocationmanager-always-returns-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!