【发布时间】:2011-11-05 11:12:08
【问题描述】:
我正在开发我的第一个 iOS 应用,它使用用户的位置。
我知道设备会询问用户是否为应用启用定位服务,但我如何知道用户是否启用了呢?
【问题讨论】:
标签: iphone objective-c geolocation
我正在开发我的第一个 iOS 应用,它使用用户的位置。
我知道设备会询问用户是否为应用启用定位服务,但我如何知道用户是否启用了呢?
【问题讨论】:
标签: iphone objective-c geolocation
大概
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied
应该是答案
相关的 SO 问题是:
Checking for iOS Location Services
locationServicesEnabled test passes when they are disabled in viewDidLoad
是的,根据@albertamg 的建议,如果你实现CLLocationManagerDelegate protocol
如果用户在您请求时拒绝访问定位服务,您将收到通知
请参阅 locationManager:didChangeAuthorizationStatus: 和 locationManager:didFailWithError: 方法
【讨论】:
CLLocationManager 对象会在后续请求期间向其委托报告kCLErrorDenied 错误。