Hi All,
I need user continues location event if app in background and terminated (Not-running) mode
below is the code I'm using to get the location but still I'm not get the location continuously
import BackgroundTasks
import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var significatLocationManager: CLLocationManager?
func startSignificationLocation() {
self.significatLocationManager = CLLocationManager()
self.significatLocationManager?.delegate = self
self.significatLocationManager?.activityType = .fitness
self.significatLocationManager?.distanceFilter = 10
self.significatLocationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
self.significatLocationManager?.allowsBackgroundLocationUpdates = true
self.significatLocationManager?.pausesLocationUpdatesAutomatically = false
self.significatLocationManager?.startUpdatingLocation()
self.significatLocationManager?.startMonitoringSignificantLocationChanges()
self.significatLocationManager?.requestAlwaysAuthorization()
}
func stopAllRegionMonitoring(locationManager:CLLocationManager?){
for delRegion in (locationManager?.monitoredRegions ?? []){locationManager?.stopMonitoring(for: delRegion)}
}
}
extension AppDelegate: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.myLocation = locations.last
//call update My Location API
if (self.myLocation?.horizontalAccuracy ?? 0.0) <= (self.liveLocationTrackingRegionRadius + 15.0 ){
self.createRegion(location: self.myLocation)
} else {
manager.stopUpdatingLocation()
manager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {}
func locationManagerDidPauseLocationUpdates(_ manager: CLLocationManager) {
manager.startUpdatingLocation()
}
func locationManagerDidResumeLocationUpdates(_ manager: CLLocationManager) {
manager.startUpdatingLocation()
}
}
extension AppDelegate {
func createRegion(location:CLLocation?, type:LocationRegionMonitoringTyep = .LiveLocationTracking) {
if self.significatLocationManager == nil {
self.startSignificationLocation()
}
guard let location = location else { return }
guard CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) else{ return }
var identifier:String = "Live_Location_Tracking-" + "\(location.coordinate.latitude)" + "-" + "\(location.coordinate.longitude)"
if (self.significatLocationManager?.monitoredRegions.count ?? 0) > 10 {
self.stopAllRegionMonitoring(locationManager: self.significatLocationManager)
}
var region : CLCircularRegion?
region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude),radius: 10.0 ,identifier: identifier)
region?.notifyOnExit = true
self.significatLocationManager?.startUpdatingLocation()
if let reg = region {
self.significatLocationManager?.startMonitoring(for: reg)
}
}
func stopAllRegionMonitoring(locationManager:CLLocationManager?){
let WOMRequestId:String? = UserDefaultManager.shared.womEmergencyDetails?.data?.request?.id
for delRegion in (locationManager?.monitoredRegions ?? []){
if let reqId = WOMRequestId {
if delRegion.identifier.contains(reqId) {
locationManager?.stopMonitoring(for: delRegion)
}
} else {
locationManager?.stopMonitoring(for: delRegion)
}
}
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
if region.identifier.contains(AppConstants.WatchOverMe) {
AppDelegate.shared?.isWOMReachDestination(location: manager.location, region: region)
} }
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
self.myLocation = manager.location
manager.stopMonitoring(for: region)
self.significatLocationManager?.stopMonitoring(for: region)
manager.startUpdatingLocation()
self.significatLocationManager?.startUpdatingLocation()
self.createRegion(location: self.myLocation)
//update M yLocation API
if region.identifier.contains( AppConstants.WatchOverMe ) {
TabBarController.isWOMReachDestinationAlertShown = false
}
}
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) {
self.myLocation = manager.location
self.createRegion(location: self.myLocation)
}
}
extension AppDelegate {
func applicationDidEnterBackground(_ application: UIApplication) {
self.scheduleBackgroundTask()
}
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
completionHandler(.newData)
}
func registerBGTask(){
BGTaskScheduler.shared.register(forTaskWithIdentifier: self.getBGTaskIdentifier(), using: nil) { task in
self.handleBackgroundTask(task: task as! BGAppRefreshTask)
}
}
func handleBackgroundTask(task: BGAppRefreshTask) {
task.setTaskCompleted(success: true)
}
func scheduleBackgroundTask() {
let request = BGAppRefreshTaskRequest(identifier: self.getBGTaskIdentifier() )
request.earliestBeginDate = Date(timeIntervalSinceNow: 10) // 30 second
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Unable to schedule background task: (error)")
}
}
func getBGTaskIdentifier()->String {
let bundleId:String = AppInfoManager.shared.bundleId + ".locationBackgroundTask"
return bundleId
}
func startLocationTrackingTimer() {
self.stopLocationTrackingTimer()
self.locationTrackingTimer = Timer.scheduledTimer(timeInterval: 1.0,target: self,
selector: #selector(self.updateUserLocation),userInfo: nil,repeats: true)
RunLoop.current.add(self.locationTrackingTimer!, forMode: .common)
}
func stopLocationTrackingTimer() {
self.locationTrackingTimer?.invalidate()
self.locationTrackingTimer = nil
}
@objc func updateUserLocation() {
if self.isSocketActive {
self.updateMyLocationAPI(fromRoam: false)
} else {
self.updateUserCurrentLocation()
}
}
}
Post
Replies
Boosts
Views
Activity
We are implementing indoor positioning and proximity sensing in our iOS app using iBeacons. We have placed multiple beacons to detect the proximity of one point of interest(POI). We are using the startRangingBeacons method in the CLLocationManager class and implementing corresponding delegates to receive the ranging information. With all required foreground and background permissions granted, when a user walks from one POI to another, beacon ranging is working as expected and we are continuously receiving the sightings in the app.
We have observed that, if user stops walking for a few minutes at a POI and then device automatically pauses the scan. Hence, we will not receive any beacon signals. When there is a movement, it performs beacon ranging again for a minute or so, then stops again for longer time even when user is walking. The interval between the pausing and resuming the service is not a constant. We have also observed that sometimes it takes more than 15 minutes to resume the service once the system pauses the ranging automatically. Is it an expected behavior? How long does it usually take for beacon ranging services to resume after the user starts moving? Is there any way we can reduce this delay between the pause and resume of ranging beacons?
Appreciate your support
CLMonitor WWDC video, it says the same name can be reused await CLMonitor("greeting") but the production iOS 17 API actually crashes. Is this the correct behaviour? (See screenshot 1)
for try await events in monitor.events should work in from the WWDC video, but the production iOS 17 API does not work and need to insert await after in keyword. Also, never received any events from the monitor (See screenshot 2)
WWDC Video: https://developer.apple.com/wwdc23/10147
I have tried to make colored annotations in mapView (shown in the commented sections) but they always appear in black. Any help would be appreciated.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "TempAnnotationView")
annotationView.canShowCallout = true
annotationView.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
let configuration = UIImage.SymbolConfiguration(pointSize: 10, weight: .thin, scale: .default)
if annotation.title == "Start" {
// let config = UIImage.SymbolConfiguration.preferringMulticolor()
// let image = UIImage(systemName: "flag.fill", withConfiguration: config)
// // palette
// let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue])
// let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2)
// // hierarchical symbols
// let config3 = UIImage.SymbolConfiguration(hierarchicalColor: .systemIndigo)
// let image3 = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config3)
// // color
// let image4 = UIImage(systemName: "cone.fill")?.withTintColor(.systemRed, renderingMode: .alwaysTemplate)
// annotationView.image = image4
annotationView.image = UIImage(systemName: "poweron", withConfiguration: configuration)
}
return annotationView
}
Hello dear developers, I am planning to make a navigation application for the swift student challenge, this navigation application will work with the internet via apple maps, is it suitable for this swift student challenge competition?
Hi everyone! I'm working on an app to submit to the Swift Student Challenge this year and wanted to get some feedback on my plan to use MapKit.
I know Apple is pretty open to using any of their frameworks for the contest. But I wanted to see if anyone had insights on whether my use of MapKit would comply with the contest rules and eligibility criteria.
Any thoughts or advice you have on properly leveraging MapKit for my submission would be much appreciated! I want to make sure I avoid any issues since this framework is so integral to my app idea. Let me know if you have built a map-based app for Swift Student Challenge before as well. Thanks!
My macOS application is trying to fetch location, but everytime LocationManager responds with locationUnknown. Application is granted with permission to access location. Issue is seen in only one device with OSVersion: 14.2.1(23C71), chipset: Apple M1 pro. Other devices with same OS don't have this issue.
My application is a background agent, means it has given UIElement in the plist.
Issue persists even after restarting device, re-installing application, re-applying location permission. But Google Chrome shows correct location when using Openstreet Map or Google Maps.
Is there any troubleshoot/alternative methods here? Any idea why it occurs?
Code:
if CLLocationManager.locationServicesEnabled() {
if #available(OSX 10.14, *) {
self.locationManager.requestLocation()
} else {
// Fallback on earlier versions
self.locationManager.startUpdatingLocation()
}
}
I need to get location in certain intervals. So After LocationManager updates I stop location with locationManager.stopUpdatingLocation() and request again after the interval.
Two separate app projects need maps or navigation:
Offline map: offline vector map of small city needed within the app (avoiding any online connection after the app's install). Apple Maps requires map tile download after installation. What is an alternative solution?
Navigation: An app with a list of locations where we don't want to build-in maps or navigation. Would it be possible to allow the user to click on a location, app copies GPS coordinates, and opens default iOS navigation app and navigates from there instead?
Working in Xcode with Swift and SwiftUI.
This problem cannot be solved and the review is not approved
Hi
I want to inquire about the data returned from CoreLocation update and whether it is accurate.
I am attempting to retrieve the local address in Japan based on the postal code, and I have observed differences in the returned data.
When calling the information retrieval function with the postal code 3360042, the returned data is as follows:
Locality: さいたま市
SubLocality: 南区
Corresponding to Japan Post:
https://www.post.japanpost.jp/cgi-zip/zipcode.php?pref=11&city=1111080&id=38748
the displayed information on the website includes "Locality + SubLocality".
When calling the information retrieval function with the postal code 1350064, the returned data is as follows:
Locality: 江東区
SubLocality: 青海
Corresponding to Japan Post japan post:
https://www.post.japanpost.jp/cgi-zip/zipcode.php?pref=11&city=1111080&id=38748
the displayed information on the website only includes "Locality" not includes SubLocality.
Is it possible that CoreLocation has been updated? The current data seems to deviate from the design of our application.
Please provide me with a solution to determine when to use "Locality + SubLocality" versus just "Locality" to obtain the local address.
Thank.
Hello there,
Mainland china user(s) have trouble accessing MapKitJS, keeps returning HTTP 401 unauthorized for https://cdn.apple-mapkit.com/ma/bootstrap?apiVersion=2&mkjsVersion=5.77.35.
The same valid JWT perfectly works for users rest of the world.
May i know is there any special handling needed for accessing mapkitJS on web from mainland china compared to rest of the world.
Advises are highly appreciated.
I am facing issue in changing the initial coordinates of map from (0,0) to any other coordinates, before going to the map screen. So that map will start from the desired coordinates , not from (0,0).
I'm trying to create an app where the user guesses their location, so I'd love to hide the road name and country in the MKLookAroundView. I have already seen some apps pull this off and I'm wondering how to do it. I tried this, but it's not working:
struct LookAroundView: UIViewControllerRepresentable {
@Binding var isExpanded: Bool
@Binding var initialScene: MKLookAroundScene?
func makeUIViewController(context: Context) -> MKLookAroundViewController {
let lookAroundViewController = MKLookAroundViewController()
lookAroundViewController.isNavigationEnabled = true
lookAroundViewController.showsRoadLabels = false // I thought this would hide road labels but it doesn't
lookAroundViewController.pointOfInterestFilter = .excludingAll
lookAroundViewController.badgePosition = .bottomTrailing
if let initialScene = initialScene {
lookAroundViewController.scene = initialScene
}
return lookAroundViewController
}
func updateUIViewController(_ uiViewController: MKLookAroundViewController, context: Context) {
uiViewController.isNavigationEnabled = isExpanded
uiViewController.showsRoadLabels = false //This was my last idea
}
}
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
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。
清除我的网路信息。
由于保存的文件较多,不打算进行还原操作。
I have a driving tracking app I'm working on that properly starts tracking and logging location when the app is in the foreground or background. I use a buffer/queue to keep recent locations so when a trip ramps up to driving speed I can record that to work back to the start location just before the trip starts. This works great, however, in background mode when the user does not have the app open it will record locations but not until a significant location change is detected. The buffering I do is lost and the location only starts tracking several hundred yards or more after the trip has started. Does anyone have any suggestions or strategies to handle this chicken and the egg scenario?
How do GPS lat and lon get written to .MOV files on iPhones? Is it programmed to export the coordinates as soon as you press record, when you press end, some other time?
If you are recording and walking or driving what location will the GPS affix to the file? I thank you all so much for your time and help.
It appears that this is the file that the location gets written to? com.apple.quicktime.location.ISO6709
Hi there,
I am trying to develop a country guessing game using MapKit and GeoJSON data. I have verified that my data creates the outline of the country properly using other methods, but I run into an error where the map clips and does not show portions of the countries or islands when zooming at certain levels of the map. I receive the warnings in the terminal "Mismatching number of indices, indexCount: 30, triangulatedIndexCount: 27" and "Triangulator failed to fully triangulate polygon: (0.1296, 0.303328), (0.108053, 0.296605), (0.0671644, 0.289883), (0.0586311, 0.281121), (0.0397156, 0.27289), (0.0323911, 0.262393), (0.0610489, 0.260732), (0.102507, 0.284671), (0.140053, 0.292602), (0.133511, 0.291167), (0.137707, 0.293659), (0.138489, 0.29872)" I am not sure what these tuple values are, or how to fix the errors, as I have adjusted my data (removing duplicate coordinates, refreshing the map, etc). How am I able to counteract these warnings, or at least get a sense of what they are asking?
We are developed app based on driver behaviour using location and sensor data.
It's working in both background and foreground using region monitoring.
Its consume more battery comparing other apps like. Its reduce 5% for every 5 to 10 mins of duration.
We are using for our app functionality
Location (Always) - every 1sec
Sensor - Accelerometer - every 20data for 1sec
Background - Region monitoring
Time Action - 1sec for 20time
Any possible way to reduce battery consuming? If any please suggest your points.
Thanks in advance for your comments.
Hey, I've developed a new audio-based navigation technology for my Master's project at Imperial College London. The main aim of it is to take away the need for an annoying voice based prompt to interrupt your music ("Turn left in 300 yards"). Instead I've created a more natural interaction where the listener's music is binaurally spatialised to provide less annoying directional information.
I've tested the product with many users and the feedback has been really positive! I just wondered whether anyone knew someone at Apple that I could have a chat with about this technology? I think it would work great if it was linked to Apple Maps, especially now with the integration of head-tracking into the Airpod Pro's.