how to work with location services

Generated on 7/30/2024

1 search

To work with location services in your app, you can leverage the new features and improvements introduced in the "What’s new in location authorization" session at WWDC 2024. Here are the key points:

  1. Declarative Authorization Goals:

    • Use CLServiceSession to declare your app's authorization goals. This new approach moves from a procedural model to a declarative one, making it easier to manage location permissions.
    • Each CLServiceSession object represents a specific authorization goal, such as full accuracy or approximate location, and can be layered as needed for different features of your app.
  2. Implicit and Explicit Service Sessions:

    • Implicit service sessions are created automatically when you iterate over live updates or monitor events using modern CoreLocation APIs.
    • If you need more control, you can create explicit service sessions by setting the NSLocationRequireExplicitServiceSession key in your app's Info.plist.
  3. Handling Different Features:

    • Align service sessions with user-facing features. For example, create a session for geotagging a photo or browsing a MapKit view.
    • Layer service sessions for features that require different levels of accuracy. For instance, hold a full accuracy session only when a feature that needs it is used.
  4. Session Lifecycle:

    • Service sessions interact with your app's lifecycle. They should be created proactively and can be held even if the app is backgrounded, ensuring that CoreLocation knows your goals and acts accordingly.
  5. Diagnostic Properties:

    • Utilize the new system of diagnostic properties to get a complete contextual understanding of your app's current authorization state and the function of any other CoreLocation API objects.

For a detailed walkthrough, you can refer to the session chapters:

These chapters will provide you with a comprehensive understanding of how to implement and manage location services in your app.