New CoreLocation APIs

Hi All,

I am currently working on an app that has some navigation functionality, and since my minimum iOS is 18 wanted to incorporate the new APIs that yield a AsyncStream of locations. I have watched both WWDC sessions, the one where the new API is introduced to retrieve the location points, and also the other video where the new authorization process for location is simplified as well.

I have an app currently working in its current state, but am noticing some weird quirks when using the CLBackgroundActivitySession to get the elevated background permission.

What I am doing here is to create this stream and the background object is below:

        return AsyncThrowingStream { continuation in
            let task = Task {

                do {

                    for try await update in CLLocationUpdate.liveUpdates(updateType) {
                        if shouldStopUpdate {
                            continuation.finish()
                            break
                        }

                        continuation.yield(update)
                    }
                } catch {
                    continuation.finish(throwing: error)
                }
            }

            state = .started(locationTask: task, background: CLBackgroundActivitySession())
        }

When I have an active navigation session going and am strongly holding this object and the user force quits the app (or I stop the target through Xcode) the navigation activity indicator in the status bar (or dynamic island) remains present. Even if I relaunch the app, start navigation again, and then call the invalidate method on the CLBackgroundActivitySession I then am seeing that navigation indicator even if I delete my app, and often need to do a full restart to get out of this state.

Is there a step I am missing, or do I not understand the way the new API works to run in the background?

The background capabilities of the new APIs are a lot greater than the old ones, including they will function even if the app is force quit.

But the location updates sticking around even if the app has been deleted does not sound right.

Are you certain there are no other apps on the device using location services? Could it be that you have multiple versions of your app on the device, and one of them might still be holding on to a session?

If you are certain that yours is the only app using location, and the location indicator stays on even after you invalidate the session and delete the app, then our engineering teams need to investigate this issue, as this might indicate an issue with iOS 18.

We'd greatly appreciate it if you could open a bug report, include crash logs and sample code or models that reproduce the issue, and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating a successful bug report.

Also, please go to https://developer.apple.com/bug-reporting/profiles-and-logs/ and follow the instructions for Location Services for iOS to install a logging profile on your device. Then reproduce the issue, and follow the instructions at the above link to create a sysdiagnose. And attach that to the Feedback report as well.


Argun Tekant /  DTS Engineer / Core Technologies

New CoreLocation APIs
 
 
Q