how do i track location in the background?

Generated on 8/2/2024

1 search

To track location in the background, you can utilize CoreLocation's service sessions. Here are some key points from the session "What’s new in location authorization" at WWDC 2024:

  1. Implicit and Explicit Sessions: CoreLocation uses both implicit and explicit sessions to manage location updates. Implicit sessions are created automatically when you start using location services, while explicit sessions are created manually by the developer to assert the app's continued interest in location updates.

  2. Handling Background and Termination: CoreLocation can resume or relaunch your app into the background when new information is ready for delivery, provided the app's authorization allows it. This ensures that even if the app is terminated, it can still track activities like workouts. For more details, you can refer to the session What’s new in location authorization (11:47).

  3. Authorization Goals: It's important to define your authorization goals clearly. For example, if your app needs full accuracy for certain features, you should hold a CL service session requiring full accuracy when those features are engaged. This proactive approach ensures that CoreLocation knows your app's needs and can act accordingly. For more information, see What’s new in location authorization (09:25).

  4. Session Lifecycle: Align your CoreLocation sessions with user-facing features. This means creating and holding CL service session objects around these feature sessions. This approach helps manage the app's lifecycle events and ensures that location updates are handled appropriately even when the app is in the background. For more details, refer to What’s new in location authorization (09:25).

Relevant Sessions

By following these guidelines, you can effectively track location in the background while ensuring that your app remains compliant with user privacy and authorization settings.