Solved! Thank you to everyone who responded.
The issue: The location permission prompt never appeared when requestWhenInUseAuthorization() was called from within a SwiftUI sheet (modal view). iOS silently ignores permission requests made from inside sheets.
The fix: Move the permission request to the parent view’s .onAppear modifier — before any sheet is presented. The LocationManager is created as a @StateObject in the main ContentView, requestPermission() is called in ContentView.onAppear, and the LocationManager instance is passed into the sheet view as an @ObservedObject.
Key points:
• The Core Location When in Use capability must be enabled in Swift Playgrounds app settings
• Use @StateObject in the parent view, @ObservedObject in the sheet
• Call requestWhenInUseAuthorization() from the main view, not from inside a sheet
• startUpdatingLocation() can still be called from within the sheet’s .onAppear
Hope this helps someone else!
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags: