Core Location

RSS for tag

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

Core Location Documentation

Posts under Core Location tag

153 Posts
Sort by:
Post marked as solved
1 Replies
69 Views
My watch app records workouts including health (with HKWorkoutSession) and location data.The watch app is on the App Store and runs without any problems since long time. I updated my own Watch Ultra to watchOS10 and my app does not properly work anymore. Everything works with the exception that the app does not receive any CLLocationManager data on the physical device. On the simulator it works perfectly. I tried several devices in the simulator and they all work. Also I de-coupled the watch from the phone, deleted the watch completely and re-installed it. My app's target is watchOS9, I tried it with watchOS10 and the problems are the same CLLocationManager has correct and valid permissions CLLocationManager is setup like this: locationManager = CLLocationManager() locationManager.delegate = self locationManager.allowsBackgroundLocationUpdates = true locationManager.activityType = .fitness locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.distanceFilter = kCLDistanceFilterNone locationManager.startUpdatingLocation() CLLocationManager's delegate is listening to: func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) The CLLocationManager is starting and correctly giving feedback on 'didFailWithError' and on 'didChangeAuthorization'. Nothing that tells me that something is wrong and points to a problem. No data is sent to didUpdateLocations. The function is never ever called. Of course I'm outside with my watch and the GPS signal is strong and I wait long enough. My app is adding the recorded workout to Apple Fitness app (my app uses HKWorkoutSession) and even though my own app does not receive any CLLocationManager data, the workout that it sent to Apple Fitness includes all the CLLocationManager data. It really seems like being a problem with my app only. Does someone have an idea or knows of a same problem? Thomas
Posted
by tompfe.
Last updated
.
Post marked as solved
22 Replies
1.1k Views
Since the iOS 17 beta 6 update, my SwiftUI-based watch app, which serves as a companion to the phone app, no longer receives any location updates. Even though the permissions are set to 'When In Use' on the phone, the CLLocation delegate returns the following error every time the app requests a location update: Error Domain=kCLErrorDomain Code=1 "(null)" - The operation couldn’t be completed. (kCLErrorDomain error 1.) Additionally, the SwiftUI map does not display the user's location, indicating that the issue is not related to my CLLocationManager implementation on the watch. While debugging on the watch, I observed that the service acknowledges the permissions as granted. On the phone, my location is displayed accurately. On watchOS 9.6, the same watch app receives location updates as expected. Furthermore, other apps on the watch receive location updates accurately, even on watchOS 10 beta. This issue is not isolated to my device; my colleagues have experienced the same problem with the TestFlight build. I suspect that there may be an issue with my project configuration, although I am unsure why this was not a problem before the watchOS 10 beta. Currently, I am attempting to resolve the issue using: Xcode 15.0 beta 8 (15A5229m) watchOS 10 21R5349b iOS 17 21A5326a It is important to note that the issue is also present in watchOS 10 21R5355a.
Posted
by OlKir1143.
Last updated
.
Post marked as solved
2 Replies
79 Views
I am having some problem with accessing the CLLLocationManager location from my widget. It works fine with Xcode 15 running on a iOS17 simulator. But running it on a iOS17 device gives me an error in the delegate: To access the location manager, I have this class: class WidgetLocationManager: NSObject, CLLocationManagerDelegate { var locationManager: CLLocationManager? private var handler: ((CLLocation?) -> Void)? override init() { super.init() DispatchQueue.main.async { print("WidgetLocationManager: init") self.locationManager = CLLocationManager() if self.locationManager!.authorizationStatus == .notDetermined { print("WidgetLocationManager: init - auth status is Undetermined") } else { print("WidgetLocationManager: init - auth status = \(self.locationManager!.authorizationStatus)") } } } func fetchLocation(handler: @escaping (CLLocation?) -> Void) { self.handler = handler self.locationManager = CLLocationManager() self.locationManager!.delegate = self self.locationManager!.requestLocation() } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if let lastLocation = locations.last { if (CLLocationCoordinate2DIsValid(lastLocation.coordinate) == true && abs(lastLocation.timestamp.timeIntervalSinceNow) < 60 && lastLocation.horizontalAccuracy < 200.0 && lastLocation.horizontalAccuracy > 0.0) { self.handler!(locations.last!) } } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("WidgetLocationManager: locationManager didFailWithError = \(error)") self.handler!(nil) } } When run on device, I get an error: WidgetLocationManager: locationManager didFailWithError = Error Domain=kCLErrorDomain Code=1 "(null)" Code = 1 in CLError is kCLErrorDenied ("Access to location or ranging has been denied by the user") This is despite getting the following output in the init method: WidgetLocationManager: init - auth status = CLAuthorizationStatus(rawValue: 4) The weird thing is that it works fine in the simulator. On device, I've tried deleting and reinstalling the app a couple of times, restarting the device, making sure the privacy setting is correct etc. Also, on the iOS17 device, when I am in the "Add Widget" page, the location manager runs fine in the preview screen, and shows the 'current location' to the user. But as soon as I add the widget to the home screen, it starts giving me this problem where the location can't be found, and I have to display an error message in the widget. I have the following keys in the Info.plist for the widget: NSLocationAlwaysAndWhenInUseUsageDescription NSLocationWhenInUseUsageDescription NSWidgetWantsLocation The app target also has the following keys in the Info.plist: NSLocationWhenInUseUsageDescription NSLocationAlwaysAndWhenInUseUsageDescription Any idea for what I can try to fix this problem? Thanks.
Posted
by zulfishah.
Last updated
.
Post not yet marked as solved
7 Replies
336 Views
I am testing my app on watchOS 10 though, After installing the app once on the Apple Watch and getting location permissions with CLLocationManager, Uninstall the app and install it again, When I check from Privacy in the Settings app on my Apple Watch, location is still allowed, but location information is no longer available. Does anyone know how to fix this?
Posted
by arimoto.
Last updated
.
Post not yet marked as solved
4 Replies
321 Views
Hello folks, I have been observing a strange behaviour on my Apple Watch Ultra. Device Environment: Apple Watch Ultra on WatchOS 10 Beta Offline Disconnected from companion iPhone Workout active: "Walking" Expected behaviour: The workout should record accurate locations (with accuracy of approximately 3-4 meters). This level of accuracy is already being achieved in the same watch (verified using several GPS status apps) when a workout is not active. . Observed behaviour: Accuracy as good as 2 meter is observed when no workouts are active, but as soon as the workout starts, the accuracy drops to a maximum of 14 meters and never gets better than this. This is confirmed to be happening every single time and is verified using several GPS status apps during the workout. Does anyone else has faced similar behaviour?
Posted Last updated
.
Post not yet marked as solved
0 Replies
50 Views
I would like to retrieve the user's current location when they are logging some information with my App Intent. When the app has been just run, this works just fine, but if it has been force quit or not run recently, the Core Location lookup times out. I have tried logging the information and using the Core Location background mode, and I can verify that the background mode is triggering because there is an indicator on the status bar, but the background mode does not seem to fire the delegate. Is there a good way to debug this? When I run the app, everything works just fine, but I can't confirm that delegate calls are going through because I can't debug from an App Intent launch. Here is the perform method from my App Intent func perform() async throws -> some ProvidesDialog { switch PersistenceController.shared.addItem(name: name, inBackground: true) { case .success(_): return .result(dialog: "Created new pin called \(name)") case .failure(let error): return .result(dialog: "There was a problem: \(error.localizedDescription)") } } addItem calls LocationManager.shared.getCurrentCoordinates: func getCurrentCoordinates(inBackground: Bool = false, callback: @escaping (CLLocation?) -> Void) { if lastSeenLocation != nil { callback(lastSeenLocation) return } if inBackground { locationManager.allowsBackgroundLocationUpdates = true locationManager.showsBackgroundLocationIndicator = false } let status = CLLocationManager.authorizationStatus() guard status == .authorizedAlways || status == .authorizedWhenInUse else { DispatchQueue.main.async { [weak self] in self?.callback?(nil) self?.locationManager.allowsBackgroundLocationUpdates = false } return } self.callback = callback locationManager.startUpdatingLocation() } The CLLocationManager delegate didUpdateLocations then calls the callback with the location and sets allowsBackgroundLocationUpdates to false. And the callback saves the location data to Core Data. What is the best practice for using Core Location in an App Intent?
Posted Last updated
.
Post not yet marked as solved
0 Replies
52 Views
I have had some trouble with that "didRangeBeacons" was called with beacons that were not present. They were preset some minutes before. And these calls never seemed to stop coming. iOS must be storing the beacons somehow. My first idea was to update the deprecated "locationManager:didRangeBeacons:inRegion" to "locationManager:didRangeBeacons:satisfyingConstraint". But the type "CLBeaconIdentityConstraint" is also deprecated, use " CLBeaconIdentityCondition" instead. How can the type be deprecated, but not the function using it? I see no API functions for this new "CLBeaconIdentityCondition" type, e.g. something like "start/stopRangingBeaconsSatisfyingCondition" or "locationManager:didRangeBeacons:satisfyingCondition:".
Posted
by Steinartc.
Last updated
.
Post not yet marked as solved
12 Replies
14k Views
Whenever I fresh install my app onto my device, it is not showing up in the Settings app. Even after trying to search it, nothing appears. I use location services and local network within my application so I need to be able to change those authorizations as it does not reliably prompt for those authorizations (I need always for location and that was removed, local network never prompts correctly). I have however seen my app appear in the settings app under privacy -> Location Services but not local network. Is this an issue with Apple or with my application? Should also be known that it does appear in settings on some devices.
Posted Last updated
.
Post marked as solved
7 Replies
1.8k Views
I just submitted a feedback for this (FB9662125) but in the spirit of “share and enjoy”… The cool new Generate Info.plist File feature in Xcode 13 crashes if you try to put an NSLocationTemporaryUsageDescriptionDictionary in your Info.plist file. Here’s a simple repro scenario: Create a minimal iOS app (no Core Data, no tests) Go to target settings → Info tab → Custom iOS Target Properties Click the (+) button on any row to begin inserting a new row Select Privacy - Location Temporary Usage Description Dictionary Click somewhere else or press Return to commit the selection Xcode crashes immediately More generally, it seems that Xcode crashes any time it tries to regenerate your Info.plist file if it contains an NSLocationTemporaryUsageDescriptionDictionary, even if (for example) you manually pasted that dictionary into the file earlier. In that case, merely tapping the (+) button in step 3 above is enough to crash it.
Posted
by Scott J.
Last updated
.
Post not yet marked as solved
1 Replies
132 Views
@Gualtier Malde, My app has not been able to send location updates in the background past 5hrs even after implementing all the changes you specified The debugger spits out nothing .... allowsBackgroundLocationUpdates must be set to TRUE distanceFilter must not be set desiredAccuracy must be kCLLocationAccuracyHundredMeters or better. If you’re using numeric values, it must be set to less than 1000 meters (We set it to 100m) We have been losing hundreds of enterprise clients as a result of this, is there something we can do to ensure the behaviour is similar or same to iOS <16.4?
Posted
by Idamezhim.
Last updated
.
Post marked as Apple Recommended
6.1k Views
Our app gets background location updates and has been working well right up to, and including iOS 16.3.1. However, testing with iOS 16.4 we are finding that background location updates stop shortly after they start. I have spoken with other developers and they’re noticing the same thing. Anyone else using background location updates finding this to be a problem?
Posted
by Scott--R.
Last updated
.
Post not yet marked as solved
6 Replies
4.3k Views
Hi!I noticed a strange behavior on MapKit when using the iOS 11 clustering feature.If you add some annotations on a map (with same clusteringIdentifier and same displayPriority) MapKit will correctly merge together annotations that are close.The problem is that if you remove all the annotations and then you add them back the map will no more merge the annotation together. It’s like the clustering feature simply stop working.I don’t really know if it is a bug or if I miss something.Someone else have noticed this?Alan
Posted
by DaleOne.
Last updated
.
Post not yet marked as solved
0 Replies
141 Views
Hey yall--seemingly once in a blue moon whenever fetchLocation gets called in here from a widget that is requesting location, it calls on the manager's requestLocation, the widget will crash. Crash stack backtrace shows this: And this is the affected code: import Foundation import CoreLocation class WidgetLocationFetcher: NSObject, CLLocationManagerDelegate { let manager = CLLocationManager() private var handler: ((CLLocation?) -> Void)? override init() { super.init() DispatchQueue.main.async { self.manager.delegate = self self.manager.requestWhenInUseAuthorization() } } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { self.handler?(locations.last!) self.handler = nil } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print(error) self.handler?(nil) self.handler = nil } func fetchLocation(handler: @escaping (CLLocation?) -> Void) { self.handler = handler self.manager.requestLocation() } } I am not too sure what could even be causing this, although I am running watchOS 10 beta 8 and iPadOS 17 beta 8 on the devices experiencing this crash. Has anyone ever solved this issue?
Posted
by novalfs.
Last updated
.
Post not yet marked as solved
0 Replies
123 Views
Hi all, I have created an application that uses location services and bluetooth services. Inside AppDelegate using significant location changes I am assigning a new instance of CBCentralManager like this How long this instance is staying alive? I am noticing that it may last even five days but I am not sure which parameters affect this? class AppDelegate: UIResponder, UIApplicationDelegate ,CLLocationManagerDelegate,CBCentralManagerDelegate,UNUserNotificationCenterDelegate { private static var centralManager : CBCentralManager! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if let keys = launchOptions?.keys { if keys.contains(.location) { AppDelegate.centralManager = CBCentralManager(delegate: self, queue: nil) locationManager.requestAlwaysAuthorization() locationManager.allowsBackgroundLocationUpdates = true locationManager.pausesLocationUpdatesAutomatically = false } } return true } func centralManager(_ central: CBCentralManager, didDiscover peripheral:CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { AppDelegate.centralManager.connect(peripheral, options: nil)* } func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { AppDelegate.centralManager.connect(peripheral, options: nil) } func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { AppDelegate.centralManager.connect(peripheral, options: nil) } }
Posted
by praeto.
Last updated
.
Post not yet marked as solved
1 Replies
168 Views
Hello all, I want to ask is CLGeocoder free or we needs pay more if reach the limit 25,000 calls daily? if needs to pay, is there any information about the pricing list? Thank you,.. Have a nice day.
Posted Last updated
.
Post not yet marked as solved
0 Replies
154 Views
Hello all! Apple presented the all-new Core Location Monitor at WWDC 2023. It changes the logic of monitoring for iBeacons with a new approach of adding CLCondition-s for monitoring iBeacon values like UUID, major, and minor. This, I suppose (please do feel free to correct me) is meant to replace current (now deprecated) startMonitoring implementation. Now, we it's a fact that it is impossible to monitor more than 20 regions at once. Question: does the new CLMonitor let us bypass this limit? If not, what's the maximum number of CLConditions we can add to a CLMonitor?
Posted Last updated
.
Post not yet marked as solved
1 Replies
209 Views
We are currently experiencing a very interesting issue when accessing the location in the background with CLLocationManager. The user has given our app the "whenInUse" permission for locations and in most cases the app provides location updates even when it's in the background. However, when we started to use other navigation apps in the foreground we saw that the func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) method was called with (kCLErrorDomain error 1.). The user hasn't changed the location permission and we saw that locations were delivered once the user opened the app again. I don't see anything in the documentation explaining this issue, but I chatted with other developers that confirm that specific behavior. Am I missing something here?
Posted Last updated
.
Post marked as solved
10 Replies
9.4k Views
Hi everyone,I want to ask and to better understand about the popup that iOS will occasionnally ask the user like :"Weather" has been using your location in the background. Do you want to continue allowing this ?How often dose this occur nad how do they determine when to ask ? And is it possible to prevent this to show to the user ?I can't find any documentation, the only explanation i can find is from the presentation from WWDC 2014 video "What's New in Core Location".Thank,Pat.
Posted Last updated
.
Post not yet marked as solved
1 Replies
704 Views
Hello guys, I have an Electron app build with electron forge (v6.0.4). I was able to pass the verification via Transporter and able to install it from TestFilght. but the app was not able to run. I have tried to run the app from Terminal, I got the following error message: FATAL:mach_port_rendezvous.cc(142)] Check failed: kr == KERN_SUCCESS. bootstrap_check_in com.xxxx.yyyyy.MachPortRendezvousServer.39844: Permission denied (1100) Then I looked into the system logs, I found: 2022-12-17 22:03:10.473560 (gui/501 [100006]) : denied lookup: name = com.apple.CoreLocation.agent, flags = 0x1, requestor = AppName[39844], error = 159: Sandbox restriction 2022-12-17 22:03:10.473654 (system) : denied lookup: name = com.apple.locationd.desktop.registration, flags = 0x8, requestor = AppName[39844], error = 159: Sandbox restriction 2022-12-17 22:03:10.482191 (system) : failed lookup: name = com.epsecurity.bdconnectorservice, requestor = BDCoreIssues[162], error = 3: No such process 2022-12-17 22:03:10.537167 (gui/501/com.apple.xpc.launchd.unmanaged.AppName.39844 [39844]) : added unmanaged active 2022-12-17 22:03:10.537647 (gui/501 [100006]) : failed activation: name = com.xxxx.yyyy.MachPortRendezvousServer.39844, flags = 0x1, requestor = AppName[39844], error = 1: Operation not permitted I have tried with/without com.apple.security.personal-information.location in my entitlements file, but looks like no difference. I have spent many days on it, anyone can help?
Posted
by SongShu_.
Last updated
.
Post not yet marked as solved
1 Replies
198 Views
Hello. I am trying to create an app that detects the beacon and makes a BLE connection when the beacon is turned on while the iPhone is in sleep mode, without the app being on the app switcher. However, there are often times when beacons cannot be detected or BLE connections cannot be made. From what I've found, it's because iOS limits beacon/BLE scanning for security reasons. I know it's impossible, but is there any way to remove this restriction on scanning? If you can't, we would like to know when iOS places restrictions on scanning. If you can't, then we would like to know when iOS places restrictions on scanning and when those restrictions are lifted. Thank you very much. Development Environment: iPhone8 (iOS 13.7), iPhone13(iOS 16.0.3), macOS Monterey, MacBook Pro 2020(Intel Core i5), Xcode 14.2
Posted
by takk_0209.
Last updated
.