Core Location

RSS for tag

Obtain the geographic location and orientation of a device using Core Location.

Posts under Core Location tag

156 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

mapItemDetailSheet Not Displaying Information
I'm on MacOS 15 Beta and Xcode 16 Beta. Running iOS 18 Beta on a 15 Pro Max. I'm leveraging the .mapItemDetailSheet(item: input) option to pull up a sheet that displays the Place Card for a selection made from a List of places. This is working great on my iPhone 15 Pro Max and my iPad Pro 13. I also have the Mac Catalyst option added under: Project \ General \ Supported Destinations If I launch the app from Xcode via the play button, the app functions fine on my MacBook Pro and I get logs in Xcode, etc. However, if stop the session in Xcode and attempt to run the same app on its own on my MacBook Pro, the mapItemDetailSheet does not populate with any information. Anyone have ideas on where the disconnect could be? Why would the sheet populate with data when ran from Xcode but not when ran on its own? Again, it runs fine on the iPhone and iPad. Any ideas would be helpful and appreciated.
1
0
210
5d
Crash when CLLocationUpdate.liveUpdates is called while requesting authorization by CLServiceSession
I watched this video and programmed with this sample code as a reference. The application crashed when I toggled the switch with the following code. // // ContentView.swift // LiveUpdatesInCoreLocation // import os import SwiftUI import CoreLocation @MainActor final class ContentViewModel: ObservableObject { private let logger = Logger() @Published var updatesStarted: Bool = false { didSet { updatesStarted ? self.startLocationUpdates() : self.stopLocationUpdates() } } func startLocationUpdates() { Task { let _ = CLServiceSession(authorization: .whenInUse) for try await update in CLLocationUpdate.liveUpdates() { guard self.updatesStarted else { break } logger.debug("update location: \(update.location)") } } } func stopLocationUpdates() {} } struct ContentView: View { @StateObject private var model = ContentViewModel() var body: some View { VStack { Toggle("Location Updates", isOn: $model.updatesStarted) } .padding() } } And this is the error that occurred. Thread 8: EXC_BAD_ACCESS (code=1, address=0x10) A bad access to memory terminated the process. If you remove the below code, the error will not occur. let _ = CLServiceSession(authorization: .whenInUse) Therefore, I guess that the problem is in calling CLLocationUpdate.liveUpdates while CLServiceSession is requesting authorization. or am I doing something wrong?
1
0
89
6d
Location in the Background constant popups
We have a pair of apps that are used to monitor the location of a person and allow them to reach out for help when needed. The apps are designed to be used with persons with special needs. A large portion of our target audience is people that have cognitive disabilities. One app is used by people that monitor and help the person with needs, and the other is used by the person with needs who is not with them all the time. The issue we have is that our users have trouble understanding what to do when this verification popup appears. This popup continues to appear over and over and over. This is a severe health and safety issue for us. We find that the user is often times confused by the popup and is disabling the background location tracking preventing the needs provider from being able to track the location of the user. It would be great if there was a special Entitlement that could be granted that would prevent this 'feature' of iOS. Or possibly simply a setting that the user's provider can setup on their phone to stop the annoying and dangerous constant popups. If anybody knows of a way to prevent this popup, please let us know. Otherwise, if someone at Apple could suggest how we can make this happen in the future.
3
0
161
1w
Unexpected iOS App foregrounding
I am seeing some unexpected behavior, in particular, is seems that iOS is periodically foregrounding my test app with no user intervention. I am curious why this is. I wrote a simple test app to see how long the app would run to collect location while in the background with only "While in Use" location permission. The app will start location updates when foregrounded and continue in the background. While backgrounded, I see the blue arrow in the dynamic island as expected. What is unexpected is that every few days, I see the UI of the app displayed in the foreground, without having foregrounded it myself (and no, I did not tap the blue arrow). This is using the legacy CoreLocation apis on iOS 17.5.1. My question is how/why does this happen?
4
0
169
1w
CLLocationUpdate with the automotiveNavigation configuration spams any location changes
I am working with an app for tracking driving activity. Currently, I have code that combines CLLocationManager location updates with motion data from CMMotionActivityManager. My codebase is not straightforward and requires manual starts/stops, etc. After watching the WWDC session about CLLocationUpdate.liveUpdates (https://developer.apple.com/wwdc23/10180) with the specific LiveConfiguration.automotiveNavigation, I thought it was exactly what I needed. Moreover, the presenter mentioned that it could simplify code and remove the dependency on CMMotionActivityManager. I downloaded the demo project from here https://developer.apple.com/documentation/corelocation/adopting-live-updates-in-core-location, adapted it for iOS 17, and changed CLLocationUpdate.liveUpdates() to CLLocationUpdate.liveUpdates(.automotiveNavigation). However, the result was not what I expected. I received location updates after waking from a stationary state by lightly touching the device, which is not "automotive." Additionally, the changes to LiveConfiguration do not seem to affect the behavior. What did I do wrong? Or what is the point of LiveConfiguration that I missed? Thanks,
2
1
239
1w
Inconsistency in Location Services in macOS Apps
I am encountering some issues with location services in macOS apps. Despite including the necessary keys in the app’s info.plist, I am unable to request user location permission. Here are the details: Cannot request location permission using requestWhenInUseAuthorization(), ie., no location permission grant permissions popup is appearing. The app contains NSLocationUsageDescription in the info.plist. I have also tested by adding NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription, and NSLocationAlwaysUsageDescription, but it didn't work. So to show the location request popup, I was directly(irrespective of the authorizationStatus) requesting location using requestLocation(), which showed the location permission grant permissions popup. But then I encountered another issue. If the popup is left as it is, every time requestLocation() is called a new location request popup appears (which comes after allowing/denying the popup). Also observed that didChangeAuthorization is only called on allowing/denying the last location request pop up. Initial calls to CLLocationManager().authorizationStatus return Not Determined. When I checked the location permission state of my app on launch, I used to get not Determined for some time, even if the permission was granted. Code snippet: private var locationManager: CLLocationManager { let lm = CLLocationManager() lm.delegate = self lm.desiredAccuracy = kCLLocationAccuracyBest return lm } private var currentAuthorizationStatus: CLAuthorizationStatus { if #available(macOS 11.0, *) { return CLLocationManager().authorizationStatus } else { return CLLocationManager.authorizationStatus() } } switch currentAuthorizationStatus { case .notDetermined: print("requesting permission") locationManager.requestWhenInUseAuthorization() case .restricted, .denied: print("location permission is restricted") case .authorizedAlways, .authorizedWhenInUse, .authorized: print("requesting location") locationManager.requestLocation() @unknown default: print("Unknown error occurred") } I would appreciate any guidance or suggestions on how to resolve these issues. Thank you!
0
5
212
2w
Location Purpose String Not Updating
Hello - I am trying to add a more descriptive Location Purpose String for submitting my app to the store. I previously had a placeholder, generic string for testing. I have updated my info.plist file, but the old string is still appearing. I have 1) deleted the app from simulator device and rebuilt 2) tried pushing the version to TestFlight 3) Deleted and replaced the values in the info.plist, none of which have resolved this issue. What am I missing here?
1
0
234
2w
Crash when requesting location authorisation on app startup
I'm trying to diagnose a crash we're seeing in an app that's on TestFlight at the moment. We have the background location permission and are woken by various events, e.g. the significant location change event. I believe the app is being woken in the background and within a few seconds (about 7s in the example below) the app crashes. The crash appears to be when we are confirming what location authorisation the app currently has. As far as we know this is only happening for a single user. Any thoughts on what could be happening? Other forum posts led me to believe it was related to leaking background tasks but I didn't think that was likely after only 7s (and there's no actual mention of background tasks in the crash). Other threads in the crash log have core data relate tasks going on and while we've done a lot of work on our multi-threaded core data I could imagine that being a cause, but surely that would show as a crash on the threads involved rather than thread 0? Any help appreciated, crash log below. John AppVariant: 1:iPhone9,3:15 Beta: YES Code Type: ARM-64 (Native) Role: Non UI Parent Process: launchd [1] Date/Time: 2021-12-13 10:31:18.0065 +0000 Launch Time: 2021-12-13 10:31:11.4169 +0000 OS Version: iPhone OS 15.1 (19B74) Release Type: User Baseband Version: 6.00.00 Report Version: 104 Exception Type: EXC_CRASH (SIGKILL) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 0 Thread 0 name: Thread 0 Crashed: 0 libsystem_kernel.dylib 0x00000001bdd7cb10 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x00000001bdd7d134 mach_msg + 72 (mach_msg.c:119) 2 libdispatch.dylib 0x0000000183f9c734 _dispatch_mach_send_and_wait_for_reply + 504 (mach.c:815) 3 libdispatch.dylib 0x0000000183f9caec dispatch_mach_send_with_result_and_wait_for_reply$VARIANT$mp + 52 (mach.c:2019) 4 libxpc.dylib 0x00000001de30f458 xpc_connection_send_message_with_reply_sync + 236 (connection.c:974) 5 Foundation 0x0000000185a0387c __NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__ + 12 (NSXPCConnection.m:223) 6 Foundation 0x0000000185a09194 -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 2368 (NSXPCConnection.m:1649) 7 Foundation 0x0000000185a49f8c -[NSXPCConnection _sendSelector:withProxy:arg1:arg2:arg3:] + 148 (NSXPCConnection.m:1294) 8 Foundation 0x00000001859ece6c _NSXPCDistantObjectSimpleMessageSend3 + 80 (NSXPCDistantObject.m:282) 9 CoreLocation 0x000000018b0bba0c -[CLLocationInternalClient getAuthorizationStatus:forBundleID:orBundlePath:] + 140 (LocationInternal.m:786) 10 CoreLocation 0x000000018b0ba1fc CLInternalGetAuthorizationStatus + 268 (LocationInternal.m:2063) 11 CoreLocation 0x000000018b0df1c4 +[CLLocationManager _authorizationStatusForBundleIdentifier:bundle:] + 80 (CLClient.mm:1391)
7
4
3.1k
3w
tccutil: Failed to reset
I want to reset the permission state of location services to "notDetermined" (CLAuthorizationStatus) while developing. But using the command below gives me this error: $ tccutil reset CoreLocation tccutil: Failed to reset CoreLocation same goes for $ tccutil reset [my bundleId] tccutil: Failed to reset CoreLocation approval status for [my bunldeId Anyone know the reason for this?
3
0
309
3w
Location Permission Popup Not Appearing in SwiftUI App
Hello everyone, I'm working on a SwiftUI app that requires location services, and I've implemented a LocationManager class to handle location updates and permissions. However, I'm facing an issue where the location permission popup does not appear when the app is launched. Here is my current implementation: LocationManager.swift: import CoreLocation import SwiftUI class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { private let locationManager = CLLocationManager() @Published var userLocation: CLLocation? @Published var isAuthorized = false @Published var authorizationStatus: CLAuthorizationStatus = .notDetermined override init() { super.init() locationManager.delegate = self checkAuthorizationStatus() } func startLocationUpdates() { locationManager.startUpdatingLocation() } func stopLocationUpdates() { locationManager.stopUpdatingLocation() } func requestLocationAuthorization() { print("Requesting location authorization") DispatchQueue.main.async { self.locationManager.requestWhenInUseAuthorization() } } private func checkAuthorizationStatus() { print("Checking authorization status") authorizationStatus = locationManager.authorizationStatus print("Initial authorization status: \(authorizationStatus.rawValue)") handleAuthorizationStatus(authorizationStatus) } func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { print("Authorization status changed") authorizationStatus = manager.authorizationStatus print("New authorization status: \(authorizationStatus.rawValue)") handleAuthorizationStatus(authorizationStatus) } private func handleAuthorizationStatus(_ status: CLAuthorizationStatus) { switch status { case .authorizedAlways, .authorizedWhenInUse: DispatchQueue.main.async { self.isAuthorized = true self.startLocationUpdates() } case .notDetermined: requestLocationAuthorization() case .denied, .restricted: DispatchQueue.main.async { self.isAuthorized = false self.stopLocationUpdates() print("Location access denied or restricted") } @unknown default: DispatchQueue.main.async { self.isAuthorized = false self.stopLocationUpdates() } } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { DispatchQueue.main.async { self.userLocation = locations.last } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("Location manager error: \(error.localizedDescription)") } } MapzinApp.swift: @main struct MapzinApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate @StateObject private var locationManager = LocationManager() var body: some Scene { WindowGroup { Group { if locationManager.authorizationStatus == .notDetermined { Text("Determining location authorization status...") } else if locationManager.isAuthorized { CoordinatorView() .environmentObject(locationManager) } else { Text("Location access is required to use this app. Please enable it in Settings.") } } } } } Log input: Checking authorization status Initial authorization status: 0 Requesting location authorization Authorization status changed New authorization status: 0 Requesting location authorization Despite calling requestWhenInUseAuthorization() when the authorization status is .notDetermined, the permission popup never appears. Here are the specific steps I have taken: Checked the Info.plist to ensure the necessary keys for location usage are present: NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription NSLocationAlwaysAndWhenInUseUsageDescription Verified that the app's target settings include location services capabilities. Tested on a real device to ensure it's not a simulator issue. I'm not sure what I might be missing. Any advice or suggestions to resolve this issue would be greatly appreciated. Thank you!
1
0
283
3w
Periodic background location polling for infrequently used app
My team and I would like to develop a mechanism that collects the user’s location a few times per day, to detect when the user travels to a different country, for the user’s convenience. The app is very likely going to be opened very rarely. The user would of course be made aware of why collecting the location a few times a day is desired - namely, saving them the effort of having to remember to open the app every time they travel. My question is the following: given that the app would rarely be interacted with, what is the best strategy for collecting the location? The goal is to handle scenarios where the OS might avoid sending location events or notifications to the app. I imagine that the backend might need to intervene and send the occasional push notification to remind the user to open the app from time to time. There are 3 strategies that I’m aware of: LocationManager’s startMonitoringSignificantLocationChanges Scheduling BGAppRefreshTasks Using silent push notifications scheduled by the server. Ideally, using a location push service extension Keeping in mind the “Background execution demystified” WWDC session, documentation, and other threads, I concluded the following: The first idea is probably the least suitable, since it probably requires the app to be opened often, and the location updates would not be sent by OS if the app has been terminated from the app switcher. The second approach would also suffer from infrequent use and termination. The third approach seems not to be affected as much by infrequent usage. I understand that the 3rd strategy might also lead to the OS omitting to wake up the app when it has been terminated by the user. How would you implement this mechanism?
2
0
413
Jun ’24
Acceptable location purpose strings
Does anyone have recent experience of what App Review consider acceptable for location purpose strings these days? My map apps simply display a blue spot on the map showing your current location when you turn on the app's location button. That data doesn't leave the app; I'm not selling it to anyone, or doing anything nefarious. For years, I've had concise location purpose strings such as "Your location will be shown on the map". Now, App Review seem to find that inadequate. They say: "One or more purpose strings in the app do not sufficiently explain the use of protected resources. Purpose strings must clearly and completely describe the app's use of data and, in most cases, provide an example of how the data will be used. Next steps: Update the ... location purpose string to explain how the app will use the requested information and provide an example of how the data will be used. " I've just look at what Apple Maps uses as its purpose string, and it's just "Your location is used to show your position on the map, get directions, estimate travel times, and improve search results." I'm only doing the first of those things, so surely "Your location is used to show your position on the map" would get approved, right? Wrong! I have similar issues with the photos purpose string.
2
1
326
Jun ’24
Clarification on the correct use for CLServiceSession
While updating my app for iOS 18 I have run into some major issues with how CLMonitor and visit tracking are handled in the background. I have implemented the new CLServiceSession (i think) correctly. In my @main App struct's init method I call CLServiceSession(authorization: .always) to create a session. This is done in the foreground when the app is launched and also in the background. From what i understand this is the intended way to create a session as when the app is relaunched by the system the existing session is terminated a few moments later. What im seeing in iOS 18 vs iOS 17 is drastically less location updates being delivered to the app. i see around the same significant updates being delivered (around 1 per mile - 5 miles) but the CLMonitor.CircularGeographicConditions are being triggered at about 1 per 1 to 2 minutes regardless of the radius. When a zone is left the condition is removed in the background and a new condition is created at the next place it should be tracking. For visit tracking, it only reports a visit correctly about 10% of the time. my guess is the app is getting suspended and/or terminated and the CLServiceSession isn't correctly being reinitialized (or something completely different, i'm really not sure at this point) I would love some guidance as to the correct way to handle these updates in iOS 18. It is unclear if these are intentional limitations imposed in iOS 18, incorrect implementation on my part, or a bug in the betas. Note: startUpdatingLocation is not appropriate for this app as it is way too power hungry.
2
0
257
Jun ’24
CoreLocation compass heading is wrong
We receive a complaint from a user that the compass heading in our paragliding app differs from the heading in Compass app (preinstalled on iOS). During our research, it was found that third-party apps show the wrong compass heading. We get the compass heading according to the documentation (https://developer.apple.com/documentation/corelocation/getting-heading-and-course-information#Get-the-current-heading): func locationManager(_ manager: CLLocationManager, didUpdateHeading heading: CLHeading) { magneticHeading = heading.magneticHeading trueHeading = heading.trueHeading } The video linked below shows our app and the third-party app getting the compass heading of 270 degrees, and Compass app (preinstalled) getting the compass heading of 30 degrees. https://drive.google.com/file/d/1HPMRWWq1E_bFYZVyCeqB2Fo-AfG4q9J7/view?usp=share_link This problem appears to the user unpredictably and the correct compass heading is shown by Compass app (preinstalled). He has iPhone 15 Pro Max and iOS 17.4.1. The presence of this problem is very critical as it can cause fatal accidents.
4
0
278
Jun ’24
CLMonitor.CircularGeographicCondition Not triggering when in background on iOS 18 B1
Our test devices running the Dev Beta 1 for iOS 18 no longer recieve updates from the CLMonitor async stream (for try await event in await monitor.events) when the app is in the background and suspended. This works fine in iOS 17. I only have one CLMonitor.CircularGeographicCondition active at any given time, they switch out dynamically in the background based on the user's location. Another thing is that visit tracking and significant location changes continue to work as expected in the background. I have submitted feedback (FB13883553) but I'm curious if this is an undocumented policy change or a bug.
1
0
293
Jun ’24
How to change geolocation settings on WKWebView
We're developing an application using location feature in WKWebView. When accessing a URL that uses location information from WebView, a dialog box saying " Would Like To Use Your Current Location - Don't Allow or OK". If "Dont allow" is selected multiple times, the dialog will disappear and the location setting for that URL will be fixed as "Don't Allow". In Safari, I can change that location settings for each URL, But Application's WebView does not have such settings UI. How do I clear or change the setting so that location information is no longer available? It seems that reinstalling the application will clear the WebView location settings.
0
0
234
Jun ’24