ios – 如何启用对区域监控服务的访问?

我把这个问题简化了一下.当我在我的应用程序中创建和添加区域并询问这些区域的状态时,我在monitoringDidFailForRegion方法中看到以下内容:

操作无法完成. (kCLErrorDomain错误4.)

检查CLErrorDomain constants我看到错误4是kCLErrorRegionMonitoringDenied,它的描述如下:

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

这怎么可能?这是我的设置和我检查过的内容:

>我正在通过Xcode来查看日志语句.
>我连接到我的iPhone 5.我没有在模拟器中运行.
>我已确保半径足以监控(尽管它无关紧要).
>我已确保设置>隐私>位置服务已启用我的设备和我的应用程序.
>我已阅读Apple发布的每个核心位置和区域监控文档.
>我确保WiFi已打开,并且我有强大的蜂窝信号.如果我没有,它将无法在第一时间找到我的位置.
>我已确保didChangeAuthorizationStatus报告正确的状态:kCLAuthorizationStatusAuthorized
>我已经确保在添加我的区域之后监视确实通过观察对方法didStartMonitoringForRegion的调用开始.

我错过了什么?为什么在明确启用位置服务时会看到此错误?

解决方法

所以,我又看了一眼 documentation on Region Monitoring,我在列表中突出显示的项目中注意到了这一点:

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.

然后我检查了后台应用程序刷新(iOS 7中的新功能:设置>常规>后台应用程序刷新)已打开并可用于我的应用程序.它不是.我打开了这个功能,BOOM我的区域现在正在报告他们的状态.

这令人困惑和误导:

[CLLocationManager isMonitoringAvailableForClass:[CLRegion class]] returns YES

…即使禁用了后台应用程序刷新.我认为它会返回NO.

更新:

我已经向Apple和added an Open Radar发送了一个错误报告.

更新3-11-14:

Apple已确认这是一个错误.

以上是来客网为你收集整理的ios – 如何启用对区域监控服务的访问?全部内容,希望文章能够帮你解决ios – 如何启用对区域监控服务的访问?所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。