No pop up to ask a user’s location within the app in MacOS

I have a map tool app in MacOS which needs request Location permission to show MapUserLocationButton.

During development, the request for permission can pop up for the first run in my mac, but when it comes to the Apple review(Submission ID: 11f52f82-1d54-481a-9eed-880521fda2b3), they never see that.

My mac is Macbook air M2 2022, 14.5 (23F79).

Of course, enable App Sandbox - Location and fill up the Privacy - Location When in Use Usage Description

Code:

//
//  LocationManager.swift
//

import MapKit

@Observable
class LocationManager: NSObject {
    static let shared = LocationManager()
    
    private let manager = CLLocationManager()
    var isReady: Bool = false
    var showingAlert = false
//    var location: CLLocationCoordinate2D?
    
    var isAuthorized: Bool {
#if os(macOS)
        .authorized == manager.authorizationStatus
#else
        .authorizedWhenInUse == manager.authorizationStatus
#endif
    }
    
    private override init() {
        super.init()
        manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        setup()
    }
    
    private func setup() {
        isReady = isAuthorized
#if os(macOS)
        if CLLocationManager.locationServicesEnabled() {
            checkStatus()
        } else {
            showingAlert = true
        }
#else
        checkStatus()
#endif
    }
    
    private func checkStatus() {
        switch manager.authorizationStatus {
        case .notDetermined:
            manager.startUpdatingLocation()
#if os(macOS)
#else
            manager.requestWhenInUseAuthorization()
#endif
#if os(macOS)
        case .restricted, .denied:
            showingAlert = true
        case .authorizedAlways, .authorizedWhenInUse:
            manager.startUpdatingLocation()
#else
//        case .authorizedWhenInUse:
//            manager.requestLocation()
#endif
        default:
            break
        }
    }
}

extension LocationManager: CLLocationManagerDelegate {
    func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
        isReady = isAuthorized
        guard isReady else { return }
//        manager.requestLocation()
    }
    
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//        location = locations.last?.coordinate
    }
}
Answered by DTS Engineer in 790169022

Of course, enable App Sandbox - Location and fill up the Privacy - Location When in Use Usage Description

NSLocationWhenInUseUsageDescription is not used by macOS, and there's a note in the documentation about that. You're looking for NSLocationUsageDescription instead.

— Ed Ford,  DTS Engineer

Of course, enable App Sandbox - Location and fill up the Privacy - Location When in Use Usage Description

NSLocationWhenInUseUsageDescription is not used by macOS, and there's a note in the documentation about that. You're looking for NSLocationUsageDescription instead.

— Ed Ford,  DTS Engineer

I build a multiple platform App, so I need both Location When in Use Usage Description and Location Usage Description, right?

I can pop up the request because of Macbook air M2, do not in an intel mac if only Location When in Use Usage Description, right?

Why I cannot find the description string in the pop up window, in my air M2?

And now I find that these descriptions been put into the project file instead of the info.plist. is this a problem?

No pop up to ask a user’s location within the app in MacOS
 
 
Q