Location 服务问题纪录

来源:互联网 发布:金蝶免费进销存软件 编辑:程序博客网 时间:2024/05/17 05:12

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 

0 0