Core Location

RSS for tag

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

Posts under Core Location tag

154 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

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,
1
1
89
9h
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
3
100
4d
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
128
6d
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
215
1w
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
170
1w
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.
0
0
124
2w
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
155
2w
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
243
2w
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
198
3w
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
194
3w
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
178
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
330
2w
Location tracking on suspended app
I’m trying to track the location of the user on every 10-20 meters of the location change, I’ve managed to obtain the location updates while the application is in foreground or background using Backround modes. my issue is that I cannot get any updates after the application is terminated either by the user or by the system, I’ve tried using startMonitoringSignificantLocationChanges() but this does not fit my purpose since you get updates every 500m. Is it possible to achieve getting updates every 10 meters using “Region Monitoring”? Or is mobile device management (MDM) the only way to achieve this on an iOS device?
1
0
289
May ’24
Inquiry About Using Find My Network for Third-Party App Development
Hello everyone, I hope you’re all doing well. I have a question regarding the use of Apple's Find My network. I’m in the early stages of developing an app that would track third-party Find My-compatible tags. Before proceeding further, I want to ensure that I am compliant with Apple’s guidelines and policies. Can anyone provide insight into whether Apple allows developers to use the Find My crowd-sourced network for their own apps? Specifically, I'm interested in tracking third-party Find My tags through my app. Any guidance or resources you can share would be greatly appreciated! Thank you!
1
0
333
May ’24
Questions about Live Activities
Our app is a time reporting service with various functions around that. The user checks in at work, checks out when they go home. We thought it'd be useful to provide a live activity to show how long they have worked for. There is also a couple of other cool things we could do that users would love, but i couldn't find definitive answers to the questions below. 1. We have a geofence-based function that checks the user in when they for example arrive at work, and check them out when they go home, so that they don't have to open the app. However, this means that we will need to start and end the live activity from within a geofence trigger. Is this possible? 2. It seems that the maximum time for a live activity is 8 hours? Sometimes people work for longer... How would we solve this? i would be fine with 12 since it would solve most cases. Is it possible somehow to go beyond 8 hours up to 12? If not, is there a callback that "8 hours are up!" so that i could do a final update on the live activity from a counter to "you started working at 09:04" 3. I have seen that some live activities have buttons. It would be neat if the user can check out via a button on the live activity. However, since we take location and call our servers when checking out, we need to be able to use both the locationmanager and make a network call from the live activity. Is this possible? Thanks in advance, Cheers
0
0
327
May ’24
iOS app crash with UIKitcore - UIAlertController
I have recently submitted a new app version to the Appstore with Xcode 15.0. Unfortunately, I have started to see the below crash in the Xcode organiser > Crashes section occurring for more number of times. UIKitCore: +[UIAlertController _alertControllerContainedInViewController:] + 160 The exception trace is not leading to main() function but not pointing to any of the code line. I had used UIAlertController in the past versions to show the alerts but there is no code written in the current version code related to UIAlertController. Only from the latest version, this kind of crash started to surface. In the latest release, We have added a third party SDK and while implementing the SDK, we had added the Location and Bluetooth Permissions in Info.plist file. But as we don't want to use/track the Location and Bluetooth details from the app, the SDK team has disabled the Location and Bluetooth settings to not reflect in the tracked data. Is this behaviour creating any conflict with the UIAlertController and logging the crash? Because by default the OS tries to show the alert when the permissions exist in the plist file, but the alert will not come as the service is disabled on the SDK server settings. Is this creating any conflict and logging the crash. Please extend your help.
1
0
344
May ’24
ReverseGeocode works badly (returns nonsense)
Users of my app are complaining about incorrect GPS location decoding. I found that the bug is in the reverseGeocode, because it returns nonsensical results. Example: The user is located in Oberhausen, Deutschland at coordinates 51.482015, 6.887064. ReverseGeocode decodes the coordinates as "Oberhausen bei Kirn". It is mistaken 250 km! ReverseGeocode works like this: 51.48, 6.88 - Oberhausen (OK) 51.482, 6.887 - Oberhausen bei Kirn (Error) 51.48, 6.89 - Oberhausen (OK) Test result: If the coordinate precision is greater than 2 decimal places, the reverseGeocode does not work properly. From what the user told me, more apps behave like this. Probably all that work with precise coordinates.
1
0
313
May ’24