Get location updates in the most power-efficient way, but less frequently than with other services.
- Core Location
The visits service is the most power-efficient way of gathering location data. With this service, the system delivers location updates only when the user’s movements are noteworthy. Each update includes both the location and the amount of time spent at that location. This service is not intended for navigation or other real-time activities, but you can use to identify patterns in the user’s behavior and apply that knowledge to other parts of your app. For example, a music app might prepare a gym playlist if a user arrives at the gym at their normal workout time.
To start the visits location service, call the
start method of your location manager. With this service, the location manager ignores the values in its
desired properties, so you do not need to configure them. The location manager delivers updates to the
location method of its delegate. Listing 1 shows how to check for the availability of the visits location service and start it.
Another way to save power is to set the
pauses property of your location manager object to
true. Enabling this property lets the system reduce power consumption by disabling location hardware when the user is unlikely to be moving. Pausing updates does not diminish the quality of those updates, but can improve battery life significantly. To help the system determine when to pause updates, you must also assign an appropriate value to the
activity property of your location manager.
Receiving Visit Updates
When you start the visits location service, a recently cached value may be reported to your delegate immediately. As new visit data is obtained, the location manager calls your delegate's
location method with the updated value.
Handling Location-Related Errors
When the location manager is unable to deliver location updates, it calls the
location method of its delegate object. You should always implement this delegate method to handle any errors that might occur. For example, this method is called when the user denies authorization for your app to use location services. In such a scenario, you might want to disable location-related features and notify the user which features are unavailable. You should also stop whatever service you previously started, as demonstrated in Listing 3.