Determine which location services are active and available on the user's device.
- Core Location
Not all Core Location services are available on every device, and services may be temporarily unavailable in certain circumstances:
The device does not have the hardware needed to support the feature.
The user disabled location services in the system settings.
The user denied access to location services for your app.
The user's device is in Airplane Mode and unable to gather location data.
Background App Refresh is disabled and you are monitoring regions or using the significant-change location service, which requires that feature.
Before using any specific location service, check the availability of that service using the methods of your
CLLocation object. Table 1 lists the methods you call and explains any hardware requirements for the corresponding services.
Tells whether you can get the geographic coordinate for the user's current location. This service is generally available on all devices. See Getting the User's Location.
Tells whether you can get the user's location using the signficant-change location service. This service requires specific hardware and may not be available on all devices. See Getting the User's Location.
Tells whether you can use region monitoring to detect entry into or exit from geographic regions or iBeacon regions. Support for geographic region monitoring requires specific hardware and is generally available on all iOS devices. Support for iBeacon region monitoring requires Bluetooth hardware and is generally available on all devices. For information on how to monitor geographic regions, see Monitoring the User's Proximity to Geographic Regions. For information on how to monitor iBeacon regions, see Determining the Proximity to an iBeacon.
Tells whether the device is able to provide compass-related headings. This service requires the presence of a magnetometer. See Getting Heading and Course Information.
Tells whether you can obtain the relative distance to a nearby iBeacon. This service requires Bluetooth hardware and is generally available on all devices. See Determining the Proximity to an iBeacon.
Listing 1 shows how to check for the availability of the standard location service. Based on the availability of those services, you would enable or disable features of your app accordingly.
If you try to start a service that is unavailable, the
CLLocation object calls one of the failure-related methods of its delegate. For example, if region monitoring is unavailable, it calls the