Suspending authorization requests
Defer the system’s authorization request dialog until your app is ready.
Overview
If your app has an onboarding flow that includes obtaining location updates, you may want to defer the Core Location’s request for authorization from the user. You can inhibit the auto-prompting in your app by creating a CLServiceSession at a convenient time in your app, then iterating over its diagnostics property to determine the level of authorization the person using your app selects. The following code snippet demonstrates how to defer the prompting.
func doPromptingFlow() async {
await showHelloPrompt()
// Obtain a session. This causes Core Location to display the authorization prompt.
let session = CLServiceSession.session(authorization: .whenInUse)
// Wait for interaction with the prompot to complete (successfully or with denial).
for try await diagnostic in session.diagnostics {
if !diagnostic.authorizationRequestInProgress {
// A denial occurred.
break
}
}
await doFurtherWork()
}Add the CLRequireExplicitServiceSession property to your app’s Info.plist file to opt into this control behavior.