My app needs to track background location for a period of several hours while the user is using it, and we want to allow the user to switch apps or lock their phone while this is happening. We don't need to track location permanently and because of this, we don't want to request the "Always allow" permission.
The app requests "While in use" permission and it has the "Location updates" background mode enabled. The CLLocationManager has 'allowsBackgroundLocationUpdates' set to true, 'pausesLocationUpdatesAutomatically' false, kCLLocationAccuracyBest, kCLDistanceFilterNone, and .fitness for the activity type (we expect the user to be walking).
The app also initializes a CLBackgroundActivitySession while it is tracking location and invalidates it when done.
When I test this combination on my iPhone, it works fine. I get location tracking in the background for as long as I need it, regardless of what else I do with the phone.
However, my customer says it doesn't work for him. He is using a Wifi-only iPad with an external GPS receiver called "BadElf GPS Pro". He says that the external GPS receiver works fine with other apps on his iPad. With my app, he gets background location tracking only for a short time, and then it stops.
The app does monitor the "locationManagerDidPauseLocationUpdates" callback and posts a local notification if it gets called, but it doesn't get called. I've also confirmed with him that he is not force-quitting the app and the app is not otherwise being terminated by iOS.
Is there something I'm missing?
Maps & Location
RSS for tagLearn how to integrate MapKit and Core Location to unlock the power of location-based features in your app.
Post
Replies
Boosts
Views
Activity
We’ve set up an advanced App Clip experience that successfully launches when a user scans our QR code. However, the same App Clip invocation URL does not launch when tapping the associated Action Link on our Apple Place Card in Apple Maps. Instead of opening the App Clip, the link falls back to the website.
What We Have Done So Far:
App Clip Launched in App Store Connect: Our App Clip is approved and live on the App Store. Here is the invocation URL: https://appclip.parkzenapp.com/park?q=oJrbSIgx
Below is the QR code for our Advanced App Clip experience we are attempting to open in our Apple Maps Place card
When scanning the QR code that uses the same App Clip invocation URL, the App Clip reliably launches as expected. Here is our apple-app-site-association file, thats correctly served from the associated domain: https://appclip.parkzenapp.com/.well-known/apple-app-site-association
Add here is a screenshot showing how the appclip.parkzenapp.com domain is correctly validated.
Advanced App Clip Experience: We created and submitted an advanced App Clip Experience specifically tied to our location on Apple Maps. This App Clip Experience is approved and live. Below is an image of our set up of this Advanced App Clip Experience
Business Connect: We've created the Apple Maps Location in business connect and added the advanced App Clip experience invocation URL as an Action Link in the place card. See screenshot below.
Apple Maps Place:
https://maps.apple.com/place?auid=906421750045811407
Despite meeting these conditions, when a user taps the Action Link (the "Reserve" button in the Apple Maps Place Card), the fallback website opens rather than the App Clip.
Question:
What additional step or configuration might we be missing to ensure the Action Link on our Apple Maps place card triggers the App Clip instead of the website?
Thank you
Having multiple issues with google maps via wireless apply car play.
1.: maps freezing
2.:The direction I’m heading seems to be off and searching some times
3.: The most annoying, the audio doesn’t work when I’m using google maps for a trip.
Hello,
I'm currently migrating my app location service to use the new CLLocationUpdate.Updates.
I'm trying to understand what can fail in this AsyncSequence. Based on the previous CLError, I thought authorisation was one of them for example but it turns out that this is handled by the CLLocationUpdate where we can check different properties.
So, is there a list of errors available somewhere?
Thanks
Axel, @alpennec
I'm trying to create a link from a restaurant annotation on a map in my app (created using MapKit) that will open the Apple Maps app on an iphone. I've been using the Restaurant name, telephone number, and coordinates and cannot get applemaps to open the enhanced page (which contains photographs and customer reviews and is much more descriptive than the page that is opening, which only shows the location on a map with the phone number and coordinates. It is not that descriptive, and I'm trying to create a request that will make it very easy to jump back and forth between my app and the enhanced page on apple maps. here's what I'm using in my request: " private func openInAppleMaps() {
let coordinate = CLLocationCoordinate2D(latitude: restaurant.latitude, longitude: restaurant.longitude)
let placemark = MKPlacemark(coordinate: coordinate)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = restaurant.name
if let phone = restaurant.telephone1 {
mapItem.phoneNumber = phone
}
mapItem.openInMaps(launchOptions: [MKLaunchOptionsShowsTrafficKey: true])
}
}" the entire file is attached. Any help or advice would be much appreciated.
RestaurantCallOutBox.swift
Hello
I started using CLMonitor on my App, and I am noticing the following crash on Xcode Organizer for dozens of my app users:
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Codes: 0x0000000000000001, 0x0000000000000001
VM Region Info: 0x1 is not in any region. Bytes before following region: ………….
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT ………-…….. [ 176K] r-x/r-x SM=COW /var/containers/Bundle/Application/.........../MyApp
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler […..]
Thread 4 name:
Thread 4 Crashed:
0 libswiftCoreLocation.dylib 0x000000021680b4c8 @objc completion handler block implementation for @escaping @callee_unowned @convention(block) (@unowned CLMonitor) -> () with result type CLMonitor + 44 (<compiler-generated>:0)
1 CoreLocation 0x0000000196cdddd4 __76-[CLMonitorConfiguration vendMonitorWithIdentityAndAuthorizationAttributes:]_block_invoke + 216 (CLMonitorConfiguration.m:195)
2 libdispatch.dylib 0x0000000191138370 _dispatch_call_block_and_release + 32 (init.c:1549)
3 libdispatch.dylib 0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
4 libdispatch.dylib 0x00000001911416d8 _dispatch_lane_serial_drain + 744 (queue.c:3934)
5 libdispatch.dylib 0x00000001911421e0 _dispatch_lane_invoke + 380 (queue.c:4025)
6 libdispatch.dylib 0x000000019114d258 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:7193)
7 libdispatch.dylib 0x000000019114caa4 _dispatch_workloop_worker_thread + 540 (queue.c:6787)
8 libsystem_pthread.dylib 0x0000000211933c7c _pthread_wqthread + 288 (pthread.c:2696)
9 libsystem_pthread.dylib 0x0000000211930488 start_wqthread + 8
Does anyone have similar issue when using CLMonitor?
How can I debug / fix this issue?
Is it an CLMonitor API bug? Should I file a bug report?
Hi,
I have develop the application in the react native. Now this application is related to truck drivers. So we have added load and when they accept the load then we fetch the location to firebase. Now issue is its not working when app close (background) on physical device. We tried on simulator and its working perfectly in the background.
But when i make the build and test on physical device its not working for background task.
Loading tile overlays is slow even when the raster data is locally available on the device running iOS 18.2 and built with Xcode 16.2.
In this video (https://3dtopo.com/superSlowTileLoading.mov) it takes 38 seconds to load tiles readily available on the device. Then, the whole screen flashes when tiles that are already drawn are redrawn, making for a very poor user experience. 38 seconds to load a dozen or so small images (512x512) stored locally on the device is simply unacceptable. I can't release a product like this that I've spent the last 1.5 years building and many years developing the maps themselves. This severe issue is new since I committed to basing my app on MapKit.
Note that this issue does not occur with Apple's base map tiles.
I created a Feedback Assitant case, FB16110803, for this issue.
For the video, I disabled loading any tiles from the network and disabled loading any other data, such as polylines. Essentially all I am doing is loading the tiles stored on the device and returning them, such as:
public func loadTile(at path: MKTileOverlayPath, result: @escaping (Data?, Error?) -> Void) {
fetchData(forKey: key,
failure: {error in result(nil, error)},
success: {data in result(data, nil)})
}
open func fetchData(forKey key: String, failure fail: ((Error?) -> ())? = nil, success succeed: @escaping (Data) -> ()) {
let path = self.path(forKey: key)
do {
let data = try Data(
contentsOf: URL(fileURLWithPath: path),
options: Data.ReadingOptions())
succeed(data)
self.updateDiskAccessDate(atPath: path)
} catch {
if let block = fail {
block(error)
}
}
}
When I set the values of notifyOnExit and notifyOnEnter to true when registering CLCircularRegion, I checked that the didExitRegion and didEnterRegion functions are called well. However, there is a problem that they are called twice in a row every time they are called. I was wondering if this is an internal bug in the API.
There is also a stackoverflow report related to the above issue. I would appreciate your confirmation.
stackoverflow - why the didEnterRegion called twice?
Thank you.
I have App uploaded to app store but it was rejected 5 times because of the location and photo permission purpose string the idea of the app is to add compliment , choose the location on the map and some info and the location is not associated to user identity it just to show his place on the map if the place he want to pick is near him he can refuse location permission the map can open and pick the point he want and need permission for images to add images with compliment , I need help for location and images permission purpose string.
I am using CLServiceSession(authorization: .always) to start a service session for tracking Zone entry and exit in the background in my app. It has been working fine on iOS 18 until recently when we added some BGProcessingTasks.
The task runs when the user is not moving and the device is on charge, this task runs fro a bit in the background, however we are seeing that even though we are reinitializing then session upon app launch.
We have even tried to just explicitly reinitialize a session within the background task callback, but the zone tracking still continues to fail. Significant location changes are unaffected.
Timeline of events:
User Opens App,
CLServiceSession(authorization: .always) is called (assume permissions have already been granted.)
App is backgrounded
User moves outside zone and app captures the data correctly (this can happen any amount of times)
User plugs in Phone
BGProcessingTask callback is run, it may or may not be terminated early. The service session is recreated as the first action in the callback. (we have also tried putting it in the main init() function for the app, same outcome)
User moves outside zone later and app does NOT capture the data.
User is sad :(
The session seems to be reinitialized correctly when the app is launched due to CoreLocation updates.
Is this expected behaviour or a bug? Is there a good way to debug what is happening with the sessions?
Unfortunately, the WWDC sessions on this have not enlightened us about the cause of this behaviour.
I have implemented geofencing using CLMonitor.
The implementation follows this general structure:
private var monitorTask: Task<Void, Never>?
private var backgroundSession: CLBackgroundActivitySession?
func start() async {
backgroundSession = CLBackgroundActivitySession()
monitorTask = Task {
do {
let monitor = await CLMonitor("monitor")
for try await event in await monitor.events {
handleEvent(event: event)
}
} catch {}
}
}
func addSpot() async {
let monitor = await CLMonitor("monitor")
let center = CLLocationCoordinate2D(latitude: 0, longitude: 0)
let condition = CLMonitor.CircularGeographicCondition(center: center, radius: 100)
await monitor.add(condition, identifier: "sample-1")
}
When the app is not task-killed, the code inside handleEvent executes as expected.
However, after a user-initiated task kill, the functionality does not work properly.
After upgrading to iOS 18.1, apple maps is really slow. I thought it was the app so I switched to google maps and same issue. I have tried all (including reseting the iPhone) but it did not fix it. I had iPhone 15 proMax, but since nothing worked, I upgraded to i16 but .... nothing.
Any idea on how to get it fixed?
According to the following article, the CLCircularGeographicCondition has a limit whereby only 20 conditions can be monitored by any single app.
Monitoring the user’s proximity to geographic regions
While I understand the rationale behind this limit, 20 conditions seems quite low for some apps. It would be good if an app could request that the user opt-in to allowing more conditions if they understand the impact this might have on the battery etc.
I'm migrating an app presently to use CLCircularGeographicCondition instead of the now deprecated CLCircularRegion. It would be good if there were more guidance on how to use the new Core Location API's to monitor how many conditions are in use within an app and how they can be deactivated when no longer required, allowing the app to free up more of the 20 conditions available.
I'm wondering if setting the correct activityType after initializing CLLocationManager will make the location results more accurate.
locationManager = CLLocationManager()
locationManager.distanceFilter = 20
locationManager.activityType = .fitness
When using Search.autocomplete and getting the results, each search result object has coordinate which have 13 decimal places. When you use Geocoder.reverseLookup for these coordinates, it returns the wrong address and different coordinates (6 decimal places and different as well). What works is using Geocoder.lookup (with getsUserLocation as true) and putting in the Search.autocomplete displayLines (as a string) for the query. Am I doing something wrong or is this a bug?
Code:
const exampleQuery = '<example address>';
const search = new mapkit.Search({
getsUserLocation: true,
});
search.autocomplete(
exampleQuery,
(error, data) => {
if (error) {
console.error('Search error:', error);
return;
}
const { coordinate } = data.results[0];
console.log("Autocomplete coordinate", coordinate); // Lat and lng are both have 13 decimal places
const geoCoder = new mapkit.Geocoder({});
geoCoder.reverseLookup(
new mapkit.Coordinate(coordinate.latitude, coordinate.longitude),
(error, data) => {
const { formattedAddress, coordinate } = data.results[0];
console.log(formattedAddress, coordinate); // Not the same address from example query and from the search autocomplete, also the coordinate has 7 decimal places
}
);
},
{}
);
We applied for Location Push Entitlement on June. It has been several months since then but we still got not any results (either passed or rejected).
https://developer.apple.com/documentation/applemapsserverapi/creating-and-using-tokens-with-maps-server-api
This doesn't really say what to do with .p8 private key. I know I am a noob but I really don't understand Apple Doc at all. There is no example or anything like that.
const appleMapKit = await fetch("https://maps-api.apple.com/v1/token", {
headers: {
Authorization: `Bearer ${server_api_token}`,
},
});
This is what I did but because I created the token on website, server_api_token only lasts 7 days.
So, I tried to use Profile - Key to replace that. I have .p8 file and how can I use this to create the token for the server api?
In my app, I am using geofencing to perform an action when the user enter or leaves a specified location. The geofencing (CLMonitor) is active permanently, and should work across multiple app sessions or after the device is restarted. It should also work after the app was minimized or terminated. This worked perfectly with iOS 17 and prior, but with iOS 18, things changed. As soon as iOS 18 dropped, users were informing me that the app does no longer perform the entry/exit action reliably (without me making any changes to the app). Most of the times, events are missed entirely. Sometimes, after the user opens or resumes the app, duplicate events are delivered and/or events with the current time instead of the correct time of entry/exit.
I am making sure that the app has the "Always" location permission before geofencing is enabled
The gefocence radius is between 20 and 500m, but even with the max. radius specified, the geofencing is unreliable
For the same user and geofence, the entry/exit event is delivered occasionally, but not always
I am currently not using CLLocationManager.allowsBackgroundLocationUpdates (even though it's documented as "Apps that receive location updates when running in the background must include the UIBackgroundModes key (with the location value) in their app’s Info.plist file") because it wasn't necessary on iOS 17 and in my tests, using it didn't yield any improvements
In my search for what could have caused this change, I found this WWDC video about location authorization: . It appears that with iOS 18, it is now required to have an active CLServiceSession to ensure that location updates are delivered to my app. Even though the video is long (and I've watched it multiple times), some things are still unclear. For example, the docs state:
If your app actively receives and processes location updates and terminates, it should restart those APIs upon launch in order to continue receiving updates.
Also, in the video it is stated that:
... So your job, ..., is to make sure that your process launch logic knows what features it has been tasked with pursuing, and re-takes session objects...
But on the other hand it's also said that:
you can only start holding one (a CLServiceSession) when your app is in the foreground
and also
... CLMonitor.events won’t yield results when it is not in use, unless a session which was started in the foreground, ....
To summarize my questions, for the geofencing to work as described above:
when exactly do I need to create a CLServiceSession if the app is launched into the backgorund? Immediately in the applicationDidFinishLaunching method, even though the app is still in the background (applicationState is background)? Or later on, when the app is opened again by the user, e.g. in applicationDidBecomeActive (and applicationState is active)?
do I need to specify the background mode capability as noted in the Handling location updates in the background article?
do I need to create a CLBackgroundActivitySession as noted in the Handling location updates in the background article?
does it matter, which of the four initializer methods I am using to create the CLServiceSession (with CLServiceSessionAuthorizationRequirementAlways)?
does it matter if I specify NSLocationRequireExplicitServiceSession in the Info.plist or not when I already do ensure that the app has the "Always" location permission when the feature is being enabled
Does a CLServiceSession last indefinitely and should it only be invalidated once the user disables the feature?
I started getting a location error recently. I've never seen this error before and it began happeing randomly.
Here is the breakpoint. (if let locationManager........)
var currentLocation: Result<CLLocation, Error> {
get {
#if DEBUG
return .success(CLLocation(latitude: CLLocationDegrees(exactly: 0)!, longitude: CLLocationDegrees(exactly: 0)!))
#else
if let locationManager = self.locationManager {
return locationManager.currentLocation
}
return .failure(LocationError.unknown)
#endif
}
}
I've tried everything I can think of to fix the issue. It has an issue getting the users location when logging in.
I've made no changes to the code and everything has worked for years. The bug reports show nothing. I've tried re-installing Xcode, rebuilding the pods etc.
I've tried everything that you would normally do in this situation.