tes*_*ing 12 iphone cocoa-touch objective-c cllocationmanager
如果启用了位置服务,我测试了我的设备(iPod Touch 2G iOS 4.1)
permitted = [locationManager locationServicesEnabled];
Run Code Online (Sandbox Code Playgroud)
无论是否启用了位置服务,我总是得到YES.我说的是位置服务的常规按钮,而不是应用程序特定的按钮.在iOS 3.2.2的iPad上一切正常.
Pas*_*ius 35
请记住,自iOS 4.0以来[locationManager locationServicesEnabled]已弃用.请改用类方法[CLLocationManager locationServicesEnabled].
[CLLocationManager authorizationStatus]
Run Code Online (Sandbox Code Playgroud)
当你使用
[CLLocationManager locationServicesEnabled]
Run Code Online (Sandbox Code Playgroud)
然后检查是否在整个系统中启用了locationServices.因此,当您转到设置 - >位置服务时,您会看到第一个切换.该方法返回该状态的状态,与您的应用无关.
如果您需要知道您的应用是否可以访问位置服务,请使用@Pascalius答案.
当您实现位置管理器的委托时,您应该实现 didFailWithError。如果用户不允许访问位置,您将在其中收到相应的错误
\n\nApple 文档指出: \n如果用户拒绝您的应用程序\xe2\x80\x99s 使用位置服务,则此方法会报告错误kCLErrorDenied。收到此类错误后,您应该停止定位服务。
| 归档时间: |
|
| 查看次数: |
7669 次 |
| 最近记录: |