|Examples||Mac & Win||Server||Client||Guides||Statistic||FMM||Blog||Deprecated||Old|
Asks for temporary access.
|CoreLocation||11.1||✅ Yes||❌ No||❌ No||❌ No||✅ Yes|
|purpose||The purpose text.|
Returns OK or error.
DescriptionAsks for temporary access.
If your app doesn't have permission to access accurate location (see accuracyAuthorization), you can use this method to request temporary access to accurate location. This access will expire automatically, but it won't expire while the user is still engaged with your app. So, for example, while your app is in the foreground your app will retain the temporary access it was granted. Similarly, if your app starts a Continuous Background Location session with the background location indicator enabled (see -showsBackgroundLocationIndicator), your access to accurate location will remain as long as the background location indicator remains enabled. This allows your app to provide session-oriented experiences which require accurate location (e.g. fitness or navigation), even if the user has decided not to grant your app persistent access to accurate location.
When CoreLocation prepares the prompt for display, it will look at the NSLocationTemporaryUsageDescriptionDictionary key in your Info.plist. The value should be a dictionary containing usage descriptions. The purposeKey you provide to this method must correspond to an entry in that dictionary. To retrieve a localized string, CoreLocation will load your InfoPlist.strings file and try to look up a string using the purposeKey you provided. If that fails, CoreLocation will use the content provided in your Info.plist. For example, suppose your Info.plist contains the following.
<string>This app needs accurate location so it can verify that you're in a supported region.</string>
<string>This app needs accurate location so it can show you relevant results.</string>
In this case, you would be able to provide either "ExampleUsageDescription" or "AnotherUsageDescription" for the purposeKey argument. Passing any other string would result in the prompt not being displayed. To localize these usage descriptions, you would add entries for "ExampleUsageDescription" and "AnotherUsageDescription" to your InfoPlist.strings file.
CoreLocation may decide against showing the user a prompt. For example, if your app already has access to accurate location or it is currently in the background.
Due to the info plist changes, this may only work in iOS apps.
For iOS 14.0 and macOS 11.0 or newer.
- Version 11.1
- Added CoreLocation.requestTemporaryFullAccuracyAuthorization function for iOS.
This function checks for a license.
Created 16th February 2021, last changed 14th July 2022