【问题标题】:Detecting whether location services are enabled for my app检测是否为我的应用启用了位置服务
【发布时间】:2011-11-05 11:12:08
【问题描述】:

我正在开发我的第一个 iOS 应用,它使用用户的位置。

我知道设备会询问用户是否为应用启用定位服务,但我如何知道用户是否启用了呢?

【问题讨论】:

    标签: iphone objective-c geolocation


    【解决方案1】:

    大概

    [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 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2016-08-15
    • 2016-04-24
    • 1970-01-01
    • 2011-06-09
    • 2015-12-02
    相关资源
    最近更新 更多