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

161 Posts
Sort by:
Post not yet marked as solved
0 Replies
60 Views
My app is using iBeacons, and I am using func startMonitoring(for region: CLRegion). Then I am using func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) and func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) to run logic when user enters / exits certain Beacon CLBeaconRegion. Everything worked fine until recently, iOS 17 update I guess. Now after I call startMonitoring(for: region) the code works for couple hours, and then it seems my app is somehow suspended and no longer able to use CoreLocation, and my code does not work, entry and exit events to beacon regions are NOT detected. Funny enough I have some Beacon managment apps that can scan for nearby beacons, when I run one of those apps, I see on top of iPhone screen “hollow arrow” sign that marks CoreLocation being used, and then my app works for few minutes, and then again my app is suspended, and no entry/exit events into beacon regions are detected. I could figure out how to engage CoreLocation but that would rely on user intentionally opening my app, and the sole purpose of my app is to remind user when he is near one of his Beacons, so expecting user to remember to open my app defeats my apps purpose. I added Location Updates under Background Modes for my app , maybe my app has little bit more background time until it is suspended, but the problem still persists. So for any Beacon based app to work it should be able to monitor for nearby beacons, and run logic once beacons are detected. Any suggestions on how I could solve this? iOS 17 CLMonitor has BeaconIdentityCondition that can match UUID, major, minor but this is only to detect we are NEAR a Beacon (entry event), what about exit event? Should I monitor for a change in Condition from .satisfied to .unsatisfied and that transition is Exit event? My questions: Is there a way to use old code: startMonitoring(for: region) - how to fix my app so it DOES NOT get suspended, and so that this method can monitor for beacons in background with AlwaysAllow authorization? If not and I must switch to CLMonitor how do I capture Exit event - when user exits Beacon region in iOS 17 using CLMonitor? Thanks
Posted
by edinc.
Last updated
.
Post not yet marked as solved
1 Replies
47 Views
We have an app that has been using iBeacons and Geofences for 10+ years. While I cannot state when it started, we're seeing sporadic delays of hours to receive iBeacon "didExitRegion" event. I can prove this out on my iPhone running iOS 17.4.1 by setting up both a Geofence and an iBeacon in the same physical location. Yesterday, I have a several hour gap with no iBeacon events, but successfully see Geofence events. Then, an hour+ after leaving the Geofence, I get multiple didExitRegions from the same iBeacon (all without touching the app). Then this morning, everything again is working great. It "feels" like the phone stops delivering entry and exit events for the Bluetooth iBeacon for some period of time. Then, it resumes monitoring by first providing old event that were not delivered to us in real time. It's not atypical for me to see a didExitRegions event that should happen around 5pm that instead happens in the middle of the night. So far, I have not noticed this behavior for our app running on iOS 16.4.1. We're currently testing other versions of iOS to see if we can pinpoint when it started. I have a full battery so we've ruled out power saving mode. Bluetooth is on with all permissions of course. We are still receiving Geofence updates so we must have available background time. Is there any known issue in iOS 17+ that would explain this behavior? Or, is there any Feedback/Radar to explain it? Known issue?
Posted Last updated
.
Post marked as solved
4 Replies
495 Views
I am currently working on an app that uses the CLMonitor to check when the user has entered a specific region. When the user enters the region, a new region should be monitored, and the old region should be removed. Currently, I have a startMonitoring() method that contains the event handling logic: func startMonitoringConditions() { Task { monitor = await CLMonitor(MonitorNames.monitorName) if let identifiers = await monitor?.identifiers { if identifiers.count == 0 { if let coordinate = manager.location?.coordinate { await addNewRegionAtCoordinate(coordinate: coordinate) } } else { print("Previous Monitor Region is used.") } } for try await event in await monitor!.events { if let coordinate = manager.location?.coordinate { // do something... await monitor!.remove(event.identifier) await addNewRegionAtCoordinate(coordinate: coordinate) } } } } Unfortunately, adding a new region will not update the events collection in the CLMonitor, so the new region's events will not be handled in this method. Any help on how I could fix this problem would be greatly appreciated!
Posted
by selvi.
Last updated
.
Post not yet marked as solved
0 Replies
119 Views
We are developing a mobile app for our financial institution using React Native. As part of our fraud prevention measures, we need to determine the country a user is located in. However, we have noticed that the permission requests seem excessive for our requirements, especially since we only need this information if a user changes countries. Also, is there a way to only be notified when a user changes countries? Our primary goal is to identify the user's country without requesting unnecessary permissions or compromising the user experience. We want to avoid requesting location permissions if possible, as it may raise concerns among our users. What are the best practices and recommended approaches for financial institutions to determine a user's country in a React Native app, while minimizing the use of sensitive permissions? Are there any iOS-specific APIs, frameworks, or third-party libraries that can help us achieve this in a privacy-friendly manner? We would greatly appreciate any guidance, insights, or examples from the developer community to help us strike the right balance between security and user privacy. Thank you in advance for your assistance!
Posted
by jfonseca8.
Last updated
.
Post not yet marked as solved
1 Replies
422 Views
I am using CLLocationUpdate.liveUpdates() and CLBackgroundActivitySession to receive background location updates. My app has "Always" authorization, but I can not get rid of the top left "Blue bar" in any way except for by manually closing the app (swipe up in multi-app preview view). I have tried setting CLLocationManager.showsBackgroundLocationIndicator = false but it does not make any difference. How can I get rid of the blue bar in the top left corner? My project started from this WWDC23 sample code Has "always" location authorisation through CLLocationManager.requestAlwaysAuthorization() Has UIBackgroundModes - location set in Info.plist Tested multiple days with a real iPhone 14, iOS 17.2 (although an iPhone SE gen2 iOS 17.2 seems to loose the blue bar after a while)
Posted
by Wallman94.
Last updated
.
Post not yet marked as solved
0 Replies
123 Views
Hi, Per Apple the isStationary value is supposed to set to true when the device is stationary. I am trying to get a better understanding of when and how this status is changed. When and how does Apple decide when to set this to true and what is the threshold by which it is set to false. Right now when I start my app and use it is set from true to false instantly. let updates = CLLocationUpdate.liveUpdates() for try await update in updates { self.isStationary = update.isStationary I would love to know by what criteria it sets it to true otherwise I'm collecting a lot of zero speed very slight to no movements in latitude and longitude that I have to make some assumptions about filtering out of what I capture. I can't seem to find any mention of this or use case examples in any of the usual sources for examples despite having been introduced at the last WWDC 2023. Any help here would be appreciated.
Posted Last updated
.
Post not yet marked as solved
0 Replies
141 Views
Hello, I developed an application that uses iBeacons to create events, however when the app is in the terminated state I notice that part of my code is activated but the rest of the process is not activated ex : ranging beacon and notification. Is there a way to completely wake up my app when it is in terminated state or at least send a notification to the user to inform them that the app must be opened to put it back in background state so that the app working correctly?
Posted
by JMG22.
Last updated
.
Post not yet marked as solved
0 Replies
167 Views
I’m working on updating one of my apps to the asynchronous location updates API, but have been running into an unhelpful error. Here's my code: @Observable class CurrentLocation: NSObject, CLLocationManagerDelegate { private(set) var location: CLLocation? private let locationManager = CLLocationManager() override init() { super.init() self.locationManager.delegate = self self.locationManager.desiredAccuracy = kCLLocationAccuracyReduced } func requestLocation() async throws { print("requesting location") requestAccess() for try await update in CLLocationUpdate.liveUpdates() { self.location = update.location if update.isStationary { break } } } } But after calling requestLocation(), I receive the following error in the console without any location updates: {"msg":"#locationUpdater received unhandled message", "Message":kCLConnectionMessageCompensatedLocation, "self":"0x600002eaa600"} Googling this error yields absolutely no matches. I’ve ensured that I have the necessary Info.plist entries (as the old, synchronous location update code I have is also working without issues). I’d be grateful for any assistance!
Posted
by dte.
Last updated
.
Post not yet marked as solved
1 Replies
191 Views
I'm getting a report from QA that an App which normally launches from the background through significant location monitoring does not launch after the phone was restarted and the device was never unlocked. I have no idea how or where I would begin with a diagnosis of this. Anyone have any ideas? iOS: 17.2.1
Posted
by Hogdotmac.
Last updated
.
Post not yet marked as solved
1 Replies
236 Views
My MacBook Air M2 system version macOS Sonoma 14.5 Beta (23F5049f) The error occurred: from the end of March 2024 to today (April 8, 24) Problem: The system positioning information is seriously wrong, including but not limited to: time zone, Safari, map app, weather app, search app... (PS. The positioning is correct when using Google Chrome and Google Maps, but it is still wrong when using Google Maps on Safari) Background: I came to Germany from mainland China at the end of March. The Apple ID region I use is Germany. The location of my iPhone and Apple Watch can be refreshed to Germany normally, and several of my AirTags have been refreshed to Germany. Tried but failed: I searched for some bash commands to try to clear and clear the cache of the map app and system location information. rm -rf ~/Library/Containers/com.apple.Maps rm -rf ~/Library/Application\ Support/com.apple.findmy sudo rm -rf /Library/Caches/com.apple.GeoServices sudo rm -rf /Library/Caches/com.apple.locationd defaults delete com.apple.locationd.plist Turn off location services in System Settings > Privacy and Security, shut down and restart the phone, and then turn the service back on. Turn my VPN on and off. Clear my network information. Since there are many files saved, the restore operation is not planned. 我的MacBook Air M2 系统版本macOS Sonoma 14.5 Beta版(23F5049f) 错误发生时间:2024年3月底到今天(24年4月8日) 问题:系统定位信息严重错误,包括但不限于:时区、Safari、地图app、天气app、查找app... (PS.使用Google Chrome浏览器与Google Maps时定位正确,Safari使用Google Maps仍然错误) 背景: 我从3月底从中国大陆来到欧洲德国。 我使用的Apple ID地区是德国的。 我的iPhone和Apple Watch定位能正常刷新到德国,且我几个AirTag已经刷新到德国。 尝试但都未成功: 我搜索了一些bash命令尝试清除、清空地图app和系统位置信息的缓存。 rm -rf ~/Library/Containers/com.apple.Maps rm -rf ~/Library/Application\ Support/com.apple.findmy sudo rm -rf /Library/Caches/com.apple.GeoServices sudo rm -rf /Library/Caches/com.apple.locationd defaults delete com.apple.locationd.plist 关闭系统设置>隐私与安全中的定位服务,关机重启,再重开这项服务。 开关我的VPN。 清除我的网路信息。 由于保存的文件较多,不打算进行还原操作。
Posted
by TifaPlove.
Last updated
.
Post not yet marked as solved
0 Replies
183 Views
"When an iBeacon is received, a BLE scan API is called within didEnterRegion. However, if executed while the screen is off, Core Bluetooth's didDiscover does not function. Yet, if the screen is turned on once and then turned off again, didDiscover functions. Is there a way to make Core Bluetooth's didDiscover work while the screen is off?" Let me know if you need further assistance or clarification! func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) { if let beaconRegion = region as? CLBeaconRegion { startRanging(in: beaconRegion) } } func startRanging(in beaconRegion: CLBeaconRegion) { // バックグラウンドタスクを開始 bgTask = UIApplication.shared.beginBackgroundTask(expirationHandler: { [self] in print("バックグラウンドタスクの有効期限が切れ") // バックグラウンドタスクの有効期限が切れたときに、バックグラウンドタスクを終了 self.lm!.stopRangingBeacons(satisfying: beaconRegion.beaconIdentityConstraint) UIApplication.shared.endBackgroundTask(bgTask) // バックグラウンドタスクの識別子を無効 bgTask = .invalid }) // レンジング開始 self.lm!.startRangingBeacons(satisfying: beaconRegion.beaconIdentityConstraint) //サービス指定してCoreBluetoothを起動 self.centralManager.stopScan() self.centralManager.scanForPeripherals(withServices: [self.kServiceUUID], options: nil) // バックグラウンドタスク終了 let time = UIApplication.shared.backgroundTimeRemaining - 1.0 DispatchQueue.main.asyncAfter(deadline: .now() + time) { self.stopRanging(in: beaconRegion) } } func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { print("---- didDiscover ----") print("peripheral-->\(peripheral)") print("advertisementData-->\(advertisementData)") print("rssi-->\(RSSI)") print("---------------------") }
Posted
by tgrgenki.
Last updated
.
Post not yet marked as solved
0 Replies
181 Views
I'm currently working on an app that requires location-based notifications, particularly utilizing geofencing to trigger alerts when a user enters specific areas, such as when a student walks into a college campus. However, I'm curious about the behavior of such notifications when the app is fully terminated and not running in the background. Does anyone have experience implementing geofencing and location-based notifications in apps that are fully terminated? Are these functionalities still active, or does the app need to be running in the background for them to work properly? Any insights, experiences, or best practices regarding this matter would be greatly appreciated. Thank you in advance for your help!
Posted
by Mordechai.
Last updated
.
Post not yet marked as solved
0 Replies
251 Views
Hello dear when i use geolocator after i'll get this error Could not build the precompiled application for the device. Error (Xcode): Undefined symbol: OBJC_CLASS$_LocationServiceStreamHandler Error (Xcode): Undefined symbol: OBJC_CLASS$_PositionStreamHandler Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation) Error launching application on iPhone. and didn't app running so plz guide i'm a too much upset
Posted
by AliSindhi.
Last updated
.
Post not yet marked as solved
0 Replies
213 Views
I'm stuck fetching location inside iOS app's widget extension running on MacOS. locationManager.authorizationStatus == .notDetermined always returns true, meanwhile main app, running on MacOS has permission for location in MacOS system settings and doesn't have any problems with using geodata. Is it possible to fetch a location inside of iOS app's widget extension running on MacOS and if yes, what could I be doing wrong?
Posted
by stepanick.
Last updated
.
Post marked as solved
1 Replies
240 Views
Hi, Has anyone found a way to send a push notification based on beacon region entry/exit? Since iOS 17, CLBeacionRegion which inherits CLRegion that made this possible is now deprecated and replaced by CLMonitor.CLBeaconIdentityCondition. CLMonitor.CLBeaconIdentityCondition does not only work properly on the latest version of iOS, it also lacks such features like sending push notifications based on region entry/exit. Even UNLocationNotificationTrigger only accepts CLRegion which is not possible to create one using existing classes that are not deprecated.
Posted
by peter292.
Last updated
.
Post marked as solved
1 Replies
187 Views
Hi, I've discovered that my app's location can be manipulated using iMyFone. I've searched extensively online for solutions, but haven't found anything effective. Do you have any insights on how I can prevent this manipulation using Swift code? Thanks for your help in advance.
Posted
by thawdezin.
Last updated
.
Post not yet marked as solved
0 Replies
235 Views
Our app needs the location of the current user. I was able to grant access and the authorization status is 4 (= when in use). Despite of that, retrieving the location fails at almost all times. It returns the error: The operation couldn’t be completed. (kCLErrorDomain error 1.) It happens in both the simulator and on the real device. On the simulator, I can sometimes trick the location to be detected by forcing a debug location in Xcode. But this does not work on the real device. What might be the root cause of this behavior?
Posted
by waldgeist.
Last updated
.
Post not yet marked as solved
0 Replies
281 Views
I have not tested on the lower version but it seems like it is not functioning properly on iOS 17.4. It does work with CircularGeographicCondition but not with BeaconIdentityCondition. I am testing with this example code by Apple. I have typed proper UUID of my iBeacon device but it is never discovered. Some other posts say that it has not been working since iOS 17.3.1. Anyone having the same issue with me?
Posted
by peter292.
Last updated
.
Post not yet marked as solved
4 Replies
436 Views
I have a Python script that returns a scan result with scanForNetworksWithName using CoreWLAN with PyObjC. It provides info on ssid and such like the airport command. When upgrading to MacOS 14.4 however SSID is now Null. I read this was due to changes in permissions and location services needed to be enabled. I have enabled access to location services and I am able to use CoreLocation to get a location however I still do now see the SSID. Here is my script, that does both location and scan: import CoreWLAN import CoreLocation from time import sleep import re wifi_interface = CoreWLAN.CWInterface.interface() networks, error = wifi_interface.scanForNetworksWithName_error_(None, None) location_manager = CoreLocation.CLLocationManager.alloc().init() location_manager.startUpdatingLocation() max_wait = 60 # Get the current authorization status for Python for i in range(1, max_wait): authorization_status = location_manager.authorizationStatus() if authorization_status == 3 or authorization_status == 4: print("Python has been authorized for location services") break if i == max_wait-1: exit("Unable to obtain authorization, exiting") sleep(1) coord = location_manager.location().coordinate() lat, lon = coord.latitude, coord.longitude print("Your location is %f, %f" % (lat, lon)) print(f"{'SSID' : >32} {'BSSID' : <17} RSSI CHANNEL HT CC SECURITY") for i in networks: print(f"{'SSID' : >32} {'BSSID' : <17} RSSI CHANNEL HT CC SECURITY") for i in networks: print(f"{i.ssid() or '' : >32} {i.bssid() or '' : <17} {i.rssiValue() : <4} {i.channel() : <6}") It worked fine in MacOS 13.6 but with MacOS 14.4 I have the null SSID issue. We went through something similar with MacOS 10.15 where BSSID became Null. At the time I couldn't find a workaround, but sometime around MacOS 13.x I was able to generate the request for location services. After granting the request I was able to see BSSID again. It seems like we have a similar bug to this again. Thread about the BSSID issue: https://github.com/ronaldoussoren/pyobjc/issues/484
Posted
by thewade.
Last updated
.