MapKit, macOS, Swift, Location Services Question

My test MapKit desktop application generates the following issue, which I do not understand, nor for the moment would I know how to address a solution. I found searching the documentation for a possible fit-for-purpose solution to be extremely elusive with my current limited MapKit knowledge … :]

I believe the application’s PList file, Sandbox, and the associated entitlement settings to be correctly identified. The PList file contains: Privacy - Location Usage Description.

That said, the warning I am concerned about happens to be as follows:

2023-06-01 14:20:37.106631-0600 My_Map[2265:69866] [suggestions] Rejecting connection missing Suggestions entitlement; pid: 0, entitlementKey: com.apple.private.suggestions.contacts

Building the application presents the [Authorization Modal], where the application generates a series of issues when the application starts.

The [Location Manager] authorization [STATUS] changed to: <=== (As expected) [This comment occurs because I previously initiated the application to test].

The [STATUS] is [NOT DETERMINED]. <=== (As expected) [The application realizes I rebuilt the application, therefore the [MODAL] is presented again].

[The application will ignore the [MODAL] presentation if I did not rebuild the application].

The application displays the following information, listed below, [BEFORE] I acknowledge the connection:

2023-06-01 16:06:28.466642-0600 My_Map[3087:122133] [default] Failed to get state for list identifier com.apple.LSSharedFileList.ApplicationRecentDocuments Error: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" (Access to list denied) UserInfo={NSDebugDescription=Access to list denied}

2023-06-01 16:06:28.702451-0600 My_Map[3087:122133] [VKDefault] Missing MeshRenderables for ground mesh layer for (1/1) of ground tiles. Tile debug info: (Key: 0.0.1.255 t:34 kt:0, Has mesh errors: 0, MeshInstance count: 2, PendingMaterial count: 2, Invisible MeshInstances count: 0)

location manager failed with error Error Domain=kCLErrorDomain Code=1 "(null)"

2023-06-01 16:06:30.570014-0600 My_Map[3087:122133] [MKCoreLocationProvider] CLLocationManager(<CLLocationManager: 0x600003df9960>) for <MKCoreLocationProvider: 0x6000013a7900> did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)

The application presents the following information, and presents the [LOCATION IDENTIFIER – BLUE PULSING DOT] after I acknowledge access [MODAL] with [OK].

The [Location Manager] authorization [STATUS] changed to: <=== (As expected)

The [STATUS] is [AUTHORIZED]. <=== (As expected)

I did not set the [REGION] nor the [SPAN], but the application identifies the [DEFAULT LOCATION] information as follows: <=== (As expected)

The [LOCATION]: Optional(<+51.04022217,-114.09052392> +/- 35.00m (speed -1.00 mps / course -1.00) @ 2023-06-01, 4:06:33 PM Mountain Daylight Saving Time)

As a side note, I discovered I must have my [WIFI] connection to be active too ... !!!

GPS is not and never can be an option ... :]

A suggestion as to how I might address, and possibly understand this issue would be very welcome … :] I believe my application is missing a required entitlement to which I do not know how to access, and or initiate.

I must thank you in advance for your time ... :]

Best regards,

jim_k

// My Code:

import Cocoa
import MapKit
import CoreLocation

class ViewController: NSViewController, CLLocationManagerDelegate {

**//  MARK: - OUTLETS**
    
    @IBOutlet weak var theLocalTimeZoneDetailMapViewFrame: NSBox!
    // Identify the [Local Time Zone Map View]
    @IBOutlet weak var theLocalTimeZoneDetailMapView: MKMapView!
    @IBOutlet weak var theLocalTimeZoneDetailMapViewCloseButton: NSButton!
    
**//  MARK: - PROPERTIES**

    let locationManager = CLLocationManager()
    
    //  View Did Load
    override func viewDidLoad() {
        super.viewDidLoad()
        
        locationManager.delegate = self
        print("starting location update requests")
        locationManager.startUpdatingLocation()
    }
    
    //  Location Manager Function
    func locationManager(_ manager: CLLocationManager,
                         didChangeAuthorization status: CLAuthorizationStatus) {
        print("The [Location Manager] authorization [STATUS] changed to:" )
        switch status {
        case .restricted:
            print("The [STATUS] is [RESTRICTED].")
           //showLocationAuthorizationRestrictedAlert()
        case .denied:
            print("The [STATUS] is [DENIED].")
            //showLocationAuthorizationDeniedAlert()
        case .authorized:
            print("The [STATUS] is [AUTHORIZED].")
            let location = locationManager.location
            print("The [LOCATION]: \(String(describing: location))")
        case .notDetermined:
            print("The [STATUS] is [NOT DETERMINED].")
        default:
            print("unknown state: \(status)")
        }
    }
    
    //  Location Manager Error Function
    func locationManager(_ manager: CLLocationManager,
                         didFailWithError error: Error) {
        print("The [LOCATION MANAGER] failed with error \(error)" )
    }
    
**//  MARK: - DISMISS THE WINDOW**

        @IBAction func dismissDetailMapViewInformationWindow(_ sender: NSButton) {
        /// Close the window.
            NSApplication.shared.keyWindow?.close()
        }    //    <=== End of [@IBAction func dismissDetailMapViewInformationWindow(_ sender: NSButton)]
 
}   //  End of [class ViewController: NSViewController, CLLocationManagerDelegate]
Post not yet marked as solved Up vote post of jim_k Down vote post of jim_k
740 views

Replies

The application [ALERT FILES] are here:

//  MARK: - [showLocationAutorizationDeniedAlert] (and disable code)

func showLocationAuthorizationDeniedAlert() {
  
      /// Store the [suppression state] in [userDefaults] to [NOT ASK THIS QUESTION AGAIN]
          let userDefaultsKey = "dontShowLocationAuthorizationDeniedAlert"
          
      /// Check to see whether the [User] answered the question to not see the following code again
          if UserDefaults.standard.bool(forKey: userDefaultsKey) == false {
                  
              let alert = NSAlert()
              alert.messageText = "Location Authorization Denied"
              alert.informativeText = "Parental Controls ... ?"
              
              alert.alertStyle = .critical
              alert.showsSuppressionButton = true
              alert.suppressionButton?.title = "Do not show this alert again!"
              
              alert.addButton(withTitle: "OK")
              alert.addButton(withTitle: "Cancel")
              //alert.addButton(withTitle: "Use default values")
              
              let response = alert.runModal()
              
              /// Turn off the [ALERT] with [User Default Preferences] setting.
              if let supress = alert.suppressionButton {
                  
                  let state = supress.state
                  
                  switch state {
                      
                      case NSControl.StateValue.on:
                          UserDefaults.standard.set(true, forKey: userDefaultsKey)
                      default: break
                      
                  } //  End of [switch state]
                  
              }   //  <=== End of [if let supress = alert.suppressionButton]
              
              if response == .alertFirstButtonReturn {
                  
                  print("\n alertFirstButtonReturn (OK Button)")
                  
              } else {
              
                  print("Use default values")
              
              } //  End of [if response == .alertFirstButtonReturn]
              
          }   //  <=== End of [if UserDefaults.standard.bool(forKey: userDefaultsKey) == false]
      
      /// Bail and [Return] gracefully
          return
      
      }   //  <=== End of [func showLocationAuthorizationDeniedAlert()]



//  MARK: - [showLocationAutorizationRestrictedAlert] (and disable code)

func showLocationAuthorizationRestrictedAlert() {
  
      /// Store the [suppression state] in [userDefaults] to [NOT ASK THIS QUESTION AGAIN]
          let userDefaultsKey = "dontShowLocationAuthorizationRestrictedAlert"
          
      /// Check to see whether the [User] answered the question to not see the following code again
          if UserDefaults.standard.bool(forKey: userDefaultsKey) == false {
                  
              let alert = NSAlert()
              alert.messageText = "Location Authorization Restricted"
              alert.informativeText = "Check Parental Control"
              
              alert.alertStyle = .critical
              alert.showsSuppressionButton = true
              alert.suppressionButton?.title = "Do not show this alert again!"
              
              alert.addButton(withTitle: "OK")
              alert.addButton(withTitle: "Cancel")
              //alert.addButton(withTitle: "Use default values")
              
              let response = alert.runModal()
              
              /// Turn off the [ALERT] with [User Default Preferences] setting.
              if let supress = alert.suppressionButton {
                  
                  let state = supress.state
                  
                  switch state {
                      
                      case NSControl.StateValue.on:
                          UserDefaults.standard.set(true, forKey: userDefaultsKey)
                      default: break
                      
                  } //  End of [switch state]
                  
              }   //  <=== End of [if let supress = alert.suppressionButton]
              
              if response == .alertFirstButtonReturn {
                  
                  print("\n alertFirstButtonReturn (OK Button)")
                  
              } else {
              
                  print("Use default values")
              
              } //  End of [if response == .alertFirstButtonReturn]
              
          }   //  <=== End of [if UserDefaults.standard.bool(forKey: userDefaultsKey) == false]
      
      /// Bail and [Return] gracefully
          return
      
      }   //  <=== End of [func showLocationAuthorizationRestrictedAlert()]