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

142 Posts
Sort by:
Post not yet marked as solved
0 Replies
32 Views
I recently have been working an application for almost a year now, and throughout I have been using location services to update as the user moves. I updated to Ventura, and now the location manager object will not initialize and is null whenever authorization is given for location. Nothing changed besides updating to Ventura. The error I keep receiving is : "[MKCoreLocationProvider] CLLocationManager(<CLLocationManager: 0x600000b21b90>) for <MKCoreLocationProvider: 0x600003b4ca20> did fail with error: Error Domain=kCLErrorDomain Code=0 "(null)"" I have tried multiple configurations of the simulator and ensured all info.plist items were set and background task for location services enabled. Even tried some things from other people having similar problems by setting default locations and erasing content of simulators. Please help me here. I am very frustrated with this. Testing movement with physical device is more difficult and not ensured to work. Never had this problem prior to the upgrade.
Posted Last updated
.
Post not yet marked as solved
1 Replies
64 Views
Hello Developers, I've added Google maps and Apple maps to my ios project and it is successfully added. But it pic Latitude and Longitude. I'm trying to run the project on different devices and different versions. but didn't get the correct Latitude and Longitude. please let me know if you have any solution. Thank you so much 🙂
Posted Last updated
.
Post marked as Apple Recommended
36k Views
I'm seeing a runtime warning in Xcode 14 Beta 5 that says "This method should not be called on the main thread as it may lead to UI unresponsiveness." This is happening on the @main entry point of my app. See below: The warning shown gives me no insight into what's actually going wrong. I think it may be due to some Core Location code that runs when the app first opens, but is there a way for me to get some more insight into what's causing this? Or is this possibly an Xcode 14/iOS 16 bug, and this is not an issue to worry about? I'm not getting any warnings on Xcode 13/iOS 15.
Posted
by r.token.
Last updated
.
Post not yet marked as solved
0 Replies
98 Views
Hello, I noticed that when I monitor visits (on iOS 16 iPhone 12 pro but i guess it would be the same on other OS or devices), if the device time is changed no visit event would be triggered the last device time is reached. For example if it is 4:00pm and time is set to 6:00pm then switched back to the real time (i.e. 4:00pm) no event is triggered until 6:00pm. Is that a bug? Is it possible to reset the CLLocationManager and clear it's cache so it's back to triggering events no matter the last current time detected? Thank you.
Posted Last updated
.
Post not yet marked as solved
0 Replies
96 Views
CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: coord.latitude, longitude: coord.longitude)) { [weak self] placeMarks, error in       print("PLACEMARKSFIRST:")       print(placeMarks?.first)       self?.geoCodeCounter += 1               guard let place = placeMarks?.first else {         self?.selectionSubject.accept(nil)         self?.geoCodeAddress()         return       }  print("PLACEMARKSFIRST:")       print(placeMarks?.first)       self?.geoCodeCounter += 1               guard let place = placeMarks?.first else {         self?.selectionSubject.accept(nil)         self?.geoCodeAddress()         return       }       print("PLACE:")       print(place)       print(place.administrativeArea)       print(place.subAdministrativeArea)       print(place.locality)       print(place.subLocality)       print(place.thoroughfare)       print(place.subThoroughfare)       self?.geoAdministrativeArea = place.administrativeArea ?? ""       self?.geoSubAdministrativeArea = place.subAdministrativeArea ?? ""       self?.geoLocality = place.locality ?? ""       self?.geoSubLocality = place.subLocality ?? ""       self?.geoThoroughfare = place.thoroughfare ?? ""       self?.geoSubThoroughfare = place.subThoroughfare ?? "" DEBUG CODES: PLACE: Darüşşafaka Cd. 5/2, Darüşşafaka Cd. 5/2, 34457 Sarıyer İstanbul, Türkiye @ <+41.12570667,+29.02811721> +/- 100.00m, region CLCircularRegion (identifier:'<+41.12570100,+29.02817000> radius 70.68', center:<+41.12570100,+29.02817000>, radius:70.68m) Optional("İstanbul") Optional("Sarıyer") Optional("Sarıyer") Optional("Çamlıtepe") Optional("Darüşşafaka Cd.") Optional("5/2") As you see above there is a conflict between the locality inside place and the response that place.locality returns. Locality must be "Darüşşafaka". How can I fix this?
Posted Last updated
.
Post not yet marked as solved
4 Replies
774 Views
I wanted to integrate location push extension to my app I followed the documentations and applied for the entitlement. I followed these steps: I added com.apple.developer.location.push to my app entitlement as follows <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict>     <key>aps-environment</key>     <string>production</string>     <key>com.apple.developer.location.push</key>     <true/> </dict> </plist> I got the location push token and formatted it to string locationManager.startMonitoringLocationPushes(completion: { data, error in if let error = error { print(error) return } guard let data = data else { return } let token = data.reduce("", {$0 + String(format: "%02X", $1)}) print(token) }) I exported the APNS push certificate after enabling additional capabilities from the app store connect and keychain. then converted to pem format openssl x509 -in aps_development.cer -inform der -out PushCert.pem openssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12 Tried to send push using command line TOPIC="com.myapp.location-query" CERTIFICATE_FILE_NAME="./test.p12:1234" CERTIFICATE_KEY_FILE_NAME="./new2k.pem" APNS_HOST_NAME="api.sandbox.push.apple.com" DEVICE_TOKEN="FE979AB7DAC975DD19E2F977EDB9BCD13C870AFD97D8D20955039666AA5DXXXX" curl -v \ -d '{}' \ --header "apns-topic: $TOPIC" \ --header "apns-push-type: location" \ --http2 \ --cert $CERTIFICATE_FILE_NAME \ --cert-type P12 \ --http2 https://$APNS_HOST_NAME/3/device/$DEVICE_TOKEN and the response is * Trying 17.188.138.70:443... * Connected to api.sandbox.push.apple.com (17.188.138.70) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem * CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Request CERT (13): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Certificate (11): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS handshake, CERT verify (15): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 * ALPN, server accepted to use h2 * Server certificate: * subject: CN=api.development.push.apple.com; OU=management:idms.group.533599; O=Apple Inc.; ST=California; C=US * start date: Dec 10 00:29:46 2021 GMT * expire date: Jan 9 00:29:45 2023 GMT * subjectAltName: host "api.sandbox.push.apple.com" matched cert's "api.sandbox.push.apple.com" * issuer: CN=Apple Public Server RSA CA 12 - G1; O=Apple Inc.; ST=California; C=US * SSL certificate verify ok. * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * Using Stream ID: 1 (easy handle 0x11c80ce00) > POST /3/device/FE979AB7DAC975DD19E2F977EDB9BCD13C870AFD97D8D20955039666AA5DXXXX HTTP/2 > Host: api.sandbox.push.apple.com > user-agent: curl/7.77.0 > accept: */* > apns-topic: com.myapp.location-query > apns-push-type: location > content-length: 2 > content-type: application/x-www-form-urlencoded > * Connection state changed (MAX_CONCURRENT_STREAMS == 1000)! * We are completely uploaded and fine < HTTP/2 400 < apns-id: CA7EC88D-E839-318B-D9DC-DCB533F50808 < * Connection #0 to host api.sandbox.push.apple.com left intact {"reason":"TopicDisallowed"}% But I always get TopicDisallowed response Did I miss something?
Posted
by alihilal.
Last updated
.
Post not yet marked as solved
0 Replies
184 Views
In the following code, I have a LocationManager class which provides the city name of the current location via the @Published property wrapper lastSearchedCity. Then I have a SearchManagerViewModel class that should be in charge of presenting the city name on SwiftUI views based on some conditions (not currently shown in the code below) via the @Published property wrapper cityName. It properly shows the city name when I call the searchAndSetCity() method from ContentView.swift inside an onAppear modifier. My issue is that if the user turned Location Services off and turns it back On while he/she is in the ContentView.swift the Text view doesn't update, which is understandable since the searchAndSetCity() method would need to be called again. How can I call the searchAndSetCity() method located inside the SearchManagerViewModel class every time the locationManagerDidChangeAuthorization(_ manager: CLLocationManager) method is called? I believed this method is called every time the authorization status changes. LocationManager Class final class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { private let locationManager = CLLocationManager() @Published var lastSearchedCity = "" var hasFoundOnePlacemark:Bool = false func checkIfLocationServicesIsEnabled(){ DispatchQueue.global().async { if CLLocationManager.locationServicesEnabled(){ self.locationManager.delegate = self self.locationManager.desiredAccuracy = kCLLocationAccuracyBest/// kCLLocationAccuracyBest is the default self.checkLocationAuthorization() }else{ // show message: Services desabled! } } } private func checkLocationAuthorization(){ switch locationManager.authorizationStatus{ case .notDetermined: locationManager.requestWhenInUseAuthorization() case .restricted: // show message case .denied: // show message case .authorizedWhenInUse, .authorizedAlways: /// app is authorized locationManager.startUpdatingLocation() default: break } } func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { checkLocationAuthorization() } func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { hasFoundOnePlacemark = false CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)-> Void in if error != nil { self.locationManager.stopUpdatingLocation() // show error message } if placemarks!.count > 0 { if !self.hasFoundOnePlacemark{ self.hasFoundOnePlacemark = true let placemark = placemarks![0] self.lastSearchedCity = placemark.locality ?? "" } self.locationManager.stopUpdatingLocation() }else{ // no places found } }) } } SearchManagerViewModel Class class SearchManagerViewModel: ObservableObject{ @Published var cityName = "" // use this directly in SwifUI views @ObservedObject private var locationManager = LocationManager() // Call this directly fron onAppear in SwiftUI views // This method is more complex than what is shown here. It handles other things like HTTP requests etc. func searchAndSetCity(){ locationManager.checkIfLocationServicesIsEnabled() self.cityName = locationManager.lastSearchedCity } } ContentView.swift struct ContentView: View { @StateObject private var searchManager = SearchManagerViewModel() var body: some View { VStack { Text(searchManager.cityName) .font(.callout) } .onAppear{ searchManager.searchAndSetCity() } } }
Posted
by fsdolphin.
Last updated
.
Post not yet marked as solved
1 Replies
168 Views
Hello everyone, I am learning swift and learning the MapKit API. I have done a little research but the App I am attempting to build is complicated (But will save my work money). I am creating a Bus Stop Manager for the school I work at. My best logic is I have the map overlay with a menu bar where you can add locations, those locations are saved either to an Array or an SQLite database. The map pulls all (between 8-15) locations and gives turn-by-turn directions for Sub Bus Drivers. So my question is well is it possible for my logic to become reality and if so does anyone have any tutorials or suggestions on how to go about it? Thank you!
Posted
by AKlasen22.
Last updated
.
Post not yet marked as solved
0 Replies
312 Views
I want to add StartmonitoringSignificantLocationChanges in my app, but does it work in low power mode? Apple's documentation says that the background activity will turn off, does this apply to StartmonitoringSignificantLocationChanges?
Posted
by Empiric10.
Last updated
.
Post not yet marked as solved
0 Replies
244 Views
Hi, I am trying to find out the GPS/Location update rate that the iPhone14 can accomplish. Most GPS update rates are 1hz (1 location update per second). I am hoping that the newest iPhones can provide a faster update rate. Also I would like to know the accuracy of the GPS. It is 100meter, 50meter, 10meter, 3meter? Where could I find this information? Thanks, Adam
Posted Last updated
.
Post marked as solved
2 Replies
822 Views
Good afternoon! Can you tell me how to calculate the maximum speed of the user? Do you have an example of the implementation of the function? And also tell me to calculate the distance traveled? Maybe someone has an example of implementation. My application is a speedometer, used only Core Location. Thank you!
Posted
by Tact.
Last updated
.
Post not yet marked as solved
4 Replies
699 Views
In our latest two pushes to AppStore Connect, we've been getting the following message, where we hadn't previously: Dear Developer, We identified one or more issues with a recent delivery for your app, "XYZ" 1.2.3 (123). Your delivery was successful, but you may wish to correct the following issues in your next delivery:  ITMS-90683: Missing purpose string in Info.plist - Your app’s code references one or more APIs that access sensitive user data, or the app has one or more entitlements that permit such access. The Info.plist file for the “xyz.app” bundle should contain a NSLocationAlwaysAndWhenInUseUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. If you’re using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. Oddly though, we've not really made any changes to our codebase that should trigger this. Just wondering if others are seeing the same message? Has the algorithm to detect this changed recently and giving false positives? We've even uploaded a previous release (that didn't get this warning) to check if we get the warning again, and we are receiving the warning on an app upload that didn't get the warning previously. Would be good to know if any logic behind this trigger has changed, or is anyone else getting the same message when they are not expecting it? Searching our Codebase for CoreLocation reveals nothing, is there anything else that may trigger this popup and require this plist key?
Posted
by DaveLev.
Last updated
.
Post not yet marked as solved
0 Replies
267 Views
Hi developers! I have been working on a smart door app project where iPhone must detect iBeacon enabled smart door lock our company provide. The base scenario is that when a user with our app approaches our door lock, the door lock measures the approximate distance. Once the user gets close enough, the door lock advertise iBeacon packets. Then, regardless of the state of our app whether background, foreground, suspended, or terminated, our app should go through BLE communication with Core Bluetooth. In almost all cases, our app seems to behave fine. If the app has been terminated, iOS automatically launches our app in the background and our logic can handle door opening process. Thanks to the region monitoring in CoreLocation and state preservation and restoration in CoreBluetooth. However, once every few days, didEnterRegion stops firing which is responsible for background launch and initiating the door opening logic. When this happens, throughout some debugging, we have found some interesting remarks. Our door lock does advertise iBeacon packets correctly because other scanner app within the same iPhone detects the door lock. So it is not that iPhone doesn't receive the iBeacon packet. While our door lock advertises the iBeacon packets, and our app is not receiving the "didEnterRegion" event call in the background, if the user put the app in the foreground, it starts receiving "didEnterRegion" again. Likewise, just like No. 2, While our door lock advertises the iBeacon packets, and our app is not receiving the "didEnterRegion" event call in the background, instead of putting the app in the foreground, if the user goes to "Settings app" -> "Bluetooth" and wait for 2~3 seconds, iOS sends "didEnterRegion" event if the app has been in background, or launches our app in the background if the app has been terminated. The problem described in No. 2 and No. 3 is more likely to occur if there has been an error didFailWithError Error Domain=kCLErrorDomain Code=0 "(null)" So the real question in a nutshell is, in case of No. 3, why putting the app in the bluetooth menu in Settings app fixes this issue? What might be the cause of this issue? Is it definitely-my-code problem? If so, how can I tackle this instead of letting the user actively put our app in the foreground or asking user to stay in the bluetooth menu for few seconds? Any of your opinions, thoughts, or facts are highly appreciated. Thanks,
Posted Last updated
.
Post not yet marked as solved
2 Replies
298 Views
Hi, I have witnessed a situation where location updates are generated via the device far too frequently according to the CLLocatonManager settings used. There have been sporadic instances where a location update is generated by the device every 0.01 seconds for a period of seconds resulting in hundreds of updates being transmitted from the device. The app starts background location updates using startUpdatingLocation() with a distance filter set to 20m. I can see some of the lat/long co-ords generated for each location update are identical so it appears that the distance filter isn't working correctly. This is sporadic though and it appears the the device will return to correct operation after a few seconds but also after hundreds of location updates have been generated. Has anyone else witnessed this behaviour and understands the cause? Appreciate any guidance as to how to remedy.
Posted
by memis1970.
Last updated
.
Post not yet marked as solved
1 Replies
363 Views
My MacOS software uses the Location Services, previously to Ventura the user could allow the app to use or deny the use of location. Now Ventura won't show up my software name there, so the user can't enable/disable it. My software is a kind of service (main code is terminal) and I have a GUI to setup the parameters. I can't find any topic related to changes with Ventura. Anyone could help me on this?
Posted Last updated
.
Post not yet marked as solved
1 Replies
842 Views
Hello I'm building an indoor geofencing app with iBeacons. I want to detect each time a user approaches a beacon and the distance and save this data with Core Data only if the distance (proximity) to the iBeacon is close. I am using Core Location to do this but I am not using the didEnter / didExit functions as they do not provide the distance to the beacon. I am mainly using the didRange function from locationManager to get all the beacons, find the closest one and its distance. This approach works perfectly while the app is in the foreground. However, the app starts not working properly in the background. If I just change the app, the didRange function stops working, but if I lock the phone and look at the time on the lock screen, it starts working. The problem is not that the app does not work in the background, but that the functions are activated only in specific cases or times, eg. the phone is locked. I added these properties in the info.plist Privacy - Location When In Use Usage Description Privacy - Location Always and When In Use Usage Description Required background modes: Location updates I also added this code: locationManager.delegate = self locationManager.allowsBackgroundLocationUpdates = true locationManager.pausesLocationUpdatesAutomatically = false This is how I add a beacon and start monitoring it: func addBeacon(id: String, major: Int16 = 0, minor: Int16 = 0) { guard let uuid = UUID(uuidString: id) else { return } let region = CLBeaconRegion(uuid: uuid, major: CLBeaconMajorValue(major), minor: CLBeaconMinorValue(minor), identifier: id + major.description + minor.description) region.notifyOnEntry = true region.notifyOnExit = true region.notifyEntryStateOnDisplay = true self.locationManager.startMonitoring(for: region) resetValues() } func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) { let beaconRegion = region as! CLBeaconRegion if state == .inside { // Start ranging when inside a region. manager.startRangingBeacons(satisfying: beaconRegion.beaconIdentityConstraint) } else { // Stop ranging when not inside a region. manager.stopRangingBeacons(satisfying: beaconRegion.beaconIdentityConstraint) } } I am also making sure that locationManager.requestAlwaysAuthorization() is always true Do you have any ideas why it is not always working in the background? Thanks for your time.
Posted
by Jad-T.
Last updated
.
Post not yet marked as solved
1 Replies
317 Views
CLGeocoder's geocodeAddressString function always return an array with only one CLPlacemark object, independently of the string passed as a parameter. I'm using it like this: let placesArray = try await CLGeocoder().geocodeAddressString(addressString) CLGeocoder's documentation is clear: In the case of forward-geocoding requests, multiple placemark objects may be returned if the provided information yielded multiple possible locations. But that never happens. Even when passing something like "San" which should obvioulsy return an array with many CLPlacemark possibilities. I've seen this same question asked in multiple places (like here, here, here, and here) but I can't find an answer. Is this a bug? Am I doing something wrong? How can I obtain multiple possible locations from CLGeocoder? EDIT: MKLocalSearch I tried the same thing using MKLocalSearch: let searchRequest = MKLocalSearch.Request() searchRequest.naturalLanguageQuery = addressString let search = MKLocalSearch(request: searchRequest) let responses = try await search.start() Same problem, the returned MKLocalSearch.Response's mapItems array always contains only one object. Very strange.
Posted
by Flict.
Last updated
.
Post not yet marked as solved
0 Replies
320 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
0 Replies
284 Views
I have successfully applied for the com.apple.developer.location.push authority and followed the documentation and implemented everything, the notifications are successfully sent from the server with all the required headers, but the client didReceiveLocationPushPayload method did not respond.
Posted
by pkuxkxQQ.
Last updated
.