Iphone locationServicesEnabled始终返回YES

Iphone locationServicesEnabled始终返回YES,iphone,objective-c,cocoa-touch,cllocationmanager,Iphone,Objective C,Cocoa Touch,Cllocationmanager,如果启用了位置服务,我测试了我的设备(iPod Touch 2G iOS 4.1) permitted = [locationManager locationServicesEnabled]; 无论是否启用定位服务,我都会得到“是”。我指的是定位服务的通用按钮,而不是特定于应用程序的按钮。在配备iOS 3.2.2的iPad上,一切正常。当您为location manager实施委托时,您应该实施DID。如果用户不允许访问该位置,您将在那里得到相应的错误 如果用户拒绝您的应用程序使用位置服务,

如果启用了位置服务,我测试了我的设备(iPod Touch 2G iOS 4.1)

permitted = [locationManager locationServicesEnabled];

无论是否启用定位服务,我都会得到“是”。我指的是定位服务的通用按钮,而不是特定于应用程序的按钮。在配备iOS 3.2.2的iPad上,一切正常。

当您为location manager实施委托时,您应该实施DID。如果用户不允许访问该位置,您将在那里得到相应的错误


如果用户拒绝您的应用程序使用位置服务,此方法将报告
kclerordenied
错误。收到此错误后,应停止定位服务。

请记住,
[locationManager locationServicesEnabled]
已启用。 使用类方法
[CLLocationManager locationServicesEnabled]

当你使用

[CLLocationManager locationServicesEnabled]
然后检查整个系统中是否启用了locationServices。所以当你进入设置->定位服务,你会看到第一个开关。该方法返回该状态的状态,并且与您的应用程序无关


如果您需要知道您的应用程序是否可以访问位置服务,请使用@Pascalius answer。

[CLLocationManager locationServicesEnabled]将在用户设置按钮关闭时返回否,只有这样我才能获得一个否。

Swift3.1函数返回->状态:Bool和消息:String

if(![CLLocationManager locationServicesEnabled] || ([CLLocationManager authorizationStatus]!=kCLAuthorizationStatusAuthorizedWhenInUse && [CLLocationManager authorizationStatus]!=kCLAuthorizationStatusAuthorizedAlways))
{
        ; // app doesn't have access to localization to whatever you want
}
func isLocationEnabled() -> (status: Bool, message: String) {
    if CLLocationManager.locationServicesEnabled() {
        switch(CLLocationManager.authorizationStatus()) {
        case .restricted, .denied:
            return (false,"No access")
        case .authorizedAlways, .authorizedWhenInUse:
            return(true,"Access")
        }
    } else {
        return(false,"Turn On Location Services to Allow App to Determine Your Location")
    }
}

我这样做了,但我说的是启用/禁用位置服务的常规按钮(而不是每个应用程序的额外按钮)。此外,
locationServicesEnabled
如果被禁用,则不应返回YES。许多人对此感到困惑,但阅读我提供的文档链接,它将返回YES。。你必须检查一下错误。我能找到的唯一一句话就是你的答案。
locationServicesEnabled
何时返回否?它在iPad上也有。。。我之所以感到困惑,是因为
是一个布尔值,指示设备上是否启用了位置服务。
用户通常可以通过切换位置服务开关从设置应用程序中启用或禁用位置服务。
因此,通用开关和特定于应用程序的开关没有区别最有趣的是
您应该在开始位置更新之前检查此属性,以确定用户是否为当前设备启用了位置服务。如果此属性包含值“否”,并且您仍要开始位置更新,Core Location framework会向用户发出确认警报,询问是否应重新启用定位服务。
为什么要检查它是否总是返回YES,如果我不检查iOS,这对我来说很好……删除
。notDetermined
并将其添加到第二个
案例中对我来说非常有用。@WaylanSands谢谢,我根据你的评论更新了我的答案
func isLocationEnabled() -> (status: Bool, message: String) {
    if CLLocationManager.locationServicesEnabled() {
        switch(CLLocationManager.authorizationStatus()) {
        case .restricted, .denied:
            return (false,"No access")
        case .authorizedAlways, .authorizedWhenInUse:
            return(true,"Access")
        }
    } else {
        return(false,"Turn On Location Services to Allow App to Determine Your Location")
    }
}