r/macosprogramming • u/hwc • Jul 06 '24
Example of using CoreLocation on macOS
I'm trying to put together a minimal example of a program that can use the CoreLocation api on macOS.
I know that I need to add usage description keys the Info.plist, so I'm compiling in a plist file.
Here is the code I'm using now, complete with a Makefile.
When I execute the program, I just get the error message:
CLLocationManager error: The operation couldn’t be completed. (kCLErrorDomain error 1.)What am I missing? Is the codesign step neccesary? Do I need to notarize it (and how do I notarize a single executable)?
3
Upvotes
1
u/david_phillip_oster Jul 06 '24
1.) You have to have
<key>com.apple.security.personal-information.location</key><true/>in your entitlements so that the user will be prompted to allow location.2.) Don't exit on the first error. The first error, before the user has approved access to location, is expected.
3.) Make sure Location is enabled in Settings > Privacy&Security > Location Services
I moved the core location code to the
Delegate's- (void)applicationDidFinishLaunching:(NSNotification *)aNotificationso it wouldn't get called too early in the application's life cycle.2
u/david_phillip_oster Jul 06 '24
Notarizing an app made outside of Xcode is documented here