Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable access to region monitoring service?

I've simplified the question a bit. When I create and add regions in my app and interrogate the state of those regions I see the following in monitoringDidFailForRegion method:

The operation couldn’t be completed. (kCLErrorDomain error 4.)

Checking the CLErrorDomain constants I see that error 4 is kCLErrorRegionMonitoringDenied and it is described like so:

Access to the region monitoring service was denied by the user.

How is this possible? Here's my set up and what I've checked:

  • I am working through Xcode to watch log statements.
  • I am connected to my iPhone 5. I am not running in the simulator.
  • I have ensured that the radius is sufficient in size to be monitored (though it shouldn't matter).
  • I have ensured that Settings > Privacy > Location Services is on for my device and my app.
  • I've read every Core Location and Region Monitoring document Apple has ever published.
  • I have ensured that WiFi is on and that I have a strong cellular signal. If I didn't it wouldn't be able to find my location in the first place.
  • I have ensured that didChangeAuthorizationStatus reports the correct status: kCLAuthorizationStatusAuthorized
  • I have ensured that after adding my region that monitoring does in-fact begin by observing the call to the method didStartMonitoringForRegion.

What am I missing? Why do I see this error when Location Services are clearly enabled?

like image 912
Aaron Avatar asked Feb 15 '14 00:02

Aaron


People also ask

What is CLLocationManager in swift?

The object that you use to start and stop the delivery of location-related events to your app.

What is a monitoring beacon?

Monitoring Beacon Regions. Beacon region monitoring uses an iOS device's onboard radio to detect when the user is in the vicinity of Bluetooth low-energy devices that are advertising iBeacon information.

What is core location in iOS?

Core Location provides services that determine a device's geographic location, altitude, and orientation, or its position relative to a nearby iBeacon device. The framework gathers data using all available components on the device, including the Wi-Fi, GPS, Bluetooth, magnetometer, barometer, and cellular hardware.


2 Answers

So, I took yet another look at the documentation on Region Monitoring and I noticed this in the highlighted item in the list:

Determining the Availability of Region Monitoring

Before attempting to monitor any regions, your app should check to see if region monitoring is supported on the current device. There are several reasons why region monitoring might not be available:

  • The device may not have the hardware needed to support region monitoring.
  • The user might have denied the app the authorization to use region monitoring.
  • The user may have disabled location services in the Settings app.
  • The user may have disabled Background App Refresh in the Settings app, either for the device or for your app.
  • The device might be in Airplane mode and unable to power up the necessary hardware.

Then I checked that Background App Refresh (a new feature at iOS 7: Settings > General > Background App Refresh) is turned on and available for my app. It was not. I turned the feature on and BOOM my regions are reporting their state now.

It is confusing and misleading that:

[CLLocationManager isMonitoringAvailableForClass:[CLRegion class]] returns YES 

...even when Background App Refresh is disabled. I would think it would return NO.

UPDATE:

I have sent a bug report to Apple and added an Open Radar for this issue.

UPDATE 3-11-14:

Apple has confirmed that this is a bug.

like image 50
Aaron Avatar answered Oct 15 '22 19:10

Aaron


In order to do region monitoring (at least in iOS 9) you need to request "always" authorization. This not documented anywhere I could find, but it's the only way I was able to get region monitoring working.

rdar://23566600 - if you're inside apple :)

like image 34
Kenny Winker Avatar answered Oct 15 '22 21:10

Kenny Winker