core-locationwatchoswatchos-standalone-app

WatchOS 11 location authorisation dialog


For my stand-alone(!) watchOS app, I can't seem to get the location authorisation dialog to appear. The code is dead simple:

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .task {
            print("starting location update task")
            do {
                _ = CLServiceSession(authorization: .whenInUse)
                for try await update in CLLocationUpdate.liveUpdates() {
                    guard let location = update.location else { continue }
                    print("location: \(location)")
                }
            } catch {
                print("error: \(error)")
            }

        }
    }
}

#Preview {
    ContentView()
}

This should show the localisation authorisation dialog when starting the app. But nothing happens.

I did also try to use the classic, procedural API, but to no avail.


Solution

  • The answer in this case is plist keys. Here's the deal: While the old location APIs with CLLocationManager had runtime assertions for checking the required NSLocation\<xyz\>UsageDescription keys ­– thus crashing, if they were not present ­– the new APIs just silently ignore missing usage descriptions.

    Yes, this is bad API practice which should be reported.