Location 服务问题纪录

iOS定位的两个键NSLocationWhenInUseUsageDescription和:NSLocationAlwaysUsageDescription问题纪录

 

Apple文档对这两个键的描述为:

NSLocationWhenInUseUsageDescription

NSLocationWhenInUseUsageDescription (String - iOS) describes the reason why the appaccesses the user’s location normally while running in the foreground. Includethis key when your app uses location services to track the user’s currentlocation directly. This key does not support using location services to monitorregions or monitor the user’s location using the significant location changeservice. The system includes the value of this key in the alert panel displayedto the user when requesting permission to use location services.

This key is required when you use the requestWhenInUseAuthorization method of the CLLocationManager class to request authorization for locationservices. If the key is not present when you call the requestWhenInUseAuthorization method without includingthis key, the system ignores your request.

This key is supported in iOS 8.0 and later. If your Info.plist file includes both thiskey and the NSLocationUsageDescription key, the system uses thiskey and ignores the NSLocationUsageDescription key.

 

 

NSLocationAlwaysUsageDescription

NSLocationAlwaysUsageDescription (String - iOS) describes the reason why the app accesses the user’slocation information. Include this key when your app uses location services ina potentially nonobvious way while running in the foreground or the background.For example, a social app might include this key when it uses locationinformation to track the user’s location and display other users that arenearby. In this case, the fact that the app is tracking the user’s locationmight not be readily apparent. The system includes the value of this key in thealert panel displayed to the user when requesting permission to use locationservices. 

This key is required when you use the requestAlwaysAuthorization method of the CLLocationManagerclass to request authorization for locationservices. If this key is not present and you call the requestAlwaysAuthorization method, the systemignores your request and prevents your app from using location services. 

This key is supported in iOS 8.0 and later. If your Info.plist file includes both thiskey and the NSLocationUsageDescription key, the system uses thiskey and ignores the NSLocationUsageDescription key.

 

即使用定位服务时,需要在plist文件中添加两个键中的一个:NSLocationAlwaysUsageDescription  NSLocationWhenInUseUsageDescription,并在CLLocationManager 类的实例中调用两个方法中的一个requestAlwaysAuthorization  requestWhenInUseAuthorization 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值