Replacement for “purpose” property of CLLocationManager

房东的猫 提交于 2019-11-27 04:27:55

The replacement for the purpose property in iOS 6 is a new Info.plist key named NSLocationUsageDescription (aka "Privacy - Location Usage Description").

The key is documented in the Information Property List Key Reference but unfortunately it's not mentioned with the deprecation note of the purpose property.

However, the CLLocationManager.h does have this comment:

* Deprecated. Set the purpose string in Info.plist using key NSLocationUsageDescription.

In your code, you could set both the key and the purpose property (but you may want to check if the location manager responds to that selector first if/when that method is actually removed in the future).

If running under iOS 6, the location manager will use the key.
When running under less than iOS 6, the key will be ignored and the purpose property will be used.

Ralph Marschall

I just had the same issue in my App.

I found that you can now set the Activity of the CLLocationManager! You can choose different CLActivityTypes, so you don't need to write your own purpose anymore.

Here's for example for a Navigation based App

[self.gps setActivityType:CLActivityTypeAutomotiveNavigation];

Other possible CLActivityTypes are:

 - CLActivityTypeFitness
 - CLActivityTypeOther
 - CLActivityTypeOtherNavigation
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!