我有一个使用 Xcode 5 制作的项目。我有一个 ViewController,我在其中使用 CLLocationManager 获取手机位置。我已经实现了这两个:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
效果很好。
现在我用 Xcode 6 GM 打开项目,这两种方法都没有被调用(不在模拟器或设备上)。
有任何想法吗?
谢谢
请检查线程here https://stackoverflow.com/questions/24062509/ios-8-location-services-not-working?answertab=votes#tab-top
你必须注意两件事
1.
-
requestAlwaysAuthorization
- 用于背景位置
[self.locationManager requestWhenInUseAuthorization];
or
-
requestWhenInUseAuthorization
- 仅当应用程序处于活动状态时才定位
[self.locationManager requestAlwaysAuthorization];
如果您没有发出两个请求中的任何一个,iOS 将忽略 startUpdateLocation 请求。
2.
包括NSLocationAlwaysUsageDescription
or NSLocationWhenInUseUsageDescription
根据您请求的权限键入 Info.plist。该字符串将由 iOS 向用户显示,以便用户可以准确了解为什么我们的应用程序需要权限。
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)