MacOS Testflight build crashes when requesting location permissions

I'm having this issue with a mac app, where if i'm calling a CLLocationManager's requestWhenInUseAuthorization it crashes the app with some CoreLocation: __ZL25_CLClientCreateConnectionP10__CLClient_block_invoke.254+1636 error

This only happens on Testflight builds, I can't get it to reproduce when running it locally via Debug or Release mode

I can reproduce this with a clean mac app, in which I check the App Sandbox's Location field, I add the NSLocationWhenInUseUsageDescription in the info plist, and run the following code (when you press the button and the requestWhenInUseAuthorization function gets called, the crash happens):

import CoreLocation
import SwiftUI

struct ContentView: View {
    @StateObject var loc = LocationManager()

    var body: some View {
        VStack {
            Button {
                loc.startLocating()
            } label: {
                Text("run location")
            }
            Text(loc.statusString)
        }
        .padding(50)
        .frame(width: 500, height: 500)
    }
}

class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
    private let locationManager = CLLocationManager()
    @Published var locationStatus: CLAuthorizationStatus?
    @Published var lastLocation: CLLocation?

    override init() {
        super.init()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationStatus = locationManager.authorizationStatus
    }

    func startLocating() {
        locationManager.requestWhenInUseAuthorization()
    }

    var statusString: String {
        guard let status = locationStatus else {
            return "unknown"
        }

        switch status {
        case .notDetermined: return "notDetermined"
        case .authorizedWhenInUse: return "authorizedWhenInUse"
        case .authorizedAlways: return "authorizedAlways"
        case .restricted: return "restricted"
        case .denied: return "denied"
        default: return "unknown"
        }
    }

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        self.locationStatus = status
    }
}

Any ideas if I'm missing something here? seems like a pretty simple use case scenario

Accepted Answer

macOS uses the NSLocationUsageDescription instead of the ones you may be familiar with from iOS.

MacOS Testflight build crashes when requesting location permissions
 
 
Q