iOS 14-当精确的位置权限被拒绝时,如何使iBeacon唤醒应用程序? [英] iOS 14 - how to get iBeacon to wake up the app when precise location permission is denied?

查看:634
本文介绍了iOS 14-当精确的位置权限被拒绝时,如何使iBeacon唤醒应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在iOS 14.0上遇到以下问题-拥有后台位置权限,我可以这样做:

I’m running into the following problem with iOS 14.0 previously - with background location permission I could:


  • 注册iBeacon区域监视

  • 从应用切换器中杀死该应用

  • 点击屏幕,然后在控制台中看到该应用重新启动。

  • App is正在运行但不在应用程序切换器中

  • Register for iBeacon region monitoring
  • Kill the app from the app switcher
  • Tap the screen and see the app relaunched in the console.
  • App is running but is not in the app switcher

在iOS14上进行了测试,没有精确的位置,我的应用程序也不再从应用程序切换器中被唤醒。

Retested with iOS14, without precise location my app is no longer being woken up from being terminated from the app switcher.

重新启用精确位置权限,所有操作都像以前一样。

Re-enabled precise location permission and everything works as before.

我需要做什么才能使后台应用唤醒

如何检测到精确位置许可是丢失并通知用户该应用程序将无法正常运行?

How do I detect that the precise location permission is missing and notify the user that the app will not work as expected?

推荐答案

精确位置开关是iOS 14的新增功能,不幸的是,Apple并未详细记录用户将其关闭时所发生的情况。以下是基于实验的摘要:

The Precise Location switch is new to iOS 14, and the specifics of what happens when user switch it to off are unfortunately not well documented by Apple. Here is a summary based on experimentation:

启用/禁用了精确位置:

With Precise Location Enabled/Disabled:

                                      Precise Location
CoreLocation Accuracy/Function        Enabled Disabled
----------------------------------    -------- -------
kCLLocationAccuracyThreeKilometers      YES     YES
kCLLocationAccuracyReduced              YES     YES
kCLLocationAccuracyBest                 YES    DEGRADED
kCLLocationAccuracyNearestTenMeters     YES    DEGRADED
kCLLocationAccuracyHundredMeters        YES    DEGRADED
kCLLocationAccuracyKilometer            YES    DEGRADED
Beacon Monitoring                       YES      NO
Beacon Ranging                          YES      NO

                                      Precise Location
CoreBluetooth                         Enabled Disabled
----------------------------------    -------- -------
Bluetooth LE scanning                   YES       NO

                                      Precise Location
NearbyInteraction                     Enabled Disabled
----------------------------------    -------- -------
NI Ranging                              YES       NO

禁用精确位置后,对CoreLocation的经/纬度位置更新将降级为 kCLAccuracyReduced 类似于由手机信号塔数据提供的3公里精度。

When precise location is disabled, lat/lon location updates to CoreLocation will be degraded to that provided by kCLAccuracyReduced similar to 3km accuracy provided by cell tower data.

iBeacons的范围和监视被阻止-委托方法回调不取得成功,应用将不会在后台启动。

Ranging and Monitoring of iBeacons is blocked -- delegate method callbacks do not get made, and apps will not be launched in the background. Nearby Interaction ranging is blocked.

这些效果会在您关闭精确位置后立即生效。您可以通过在应用程序运行时查看日志,然后转到设置以关闭精确位置并查看行为更改来自己查看。

These effects take effect immediately when you turn off Precise Location. You can see this yourself by looking at logging from your app while it is running, then going to settings to turn off Precise Location and seeing the behavioral changes.

不幸的是,您无能为力当用户禁用精确位置时,强制iOS为您提供信标或其他位置更新。最好的办法是检测用户是否已执行此操作(使用如下代码),然后提示用户在设置中更改此设置,以便您的应用正常运行。

Unfortunately, there is nothing you can do to force iOS to give you beacon or other location updates when the user has disabled Precise Location. The best you can do is detect that the user has done this (use code like below), and then prompt the user to change this in settings so your app works properly.

        if CLLocationManager.locationServicesEnabled() {
            if #available(iOS 14.0, *) {
                switch self.locationManager.accuracyAuthorization {
                    case .fullAccuracy:
                        NSLog("Precise Location allowed")
                    case .reducedAccuracy:
                        NSLog("Precise location disabled")
                    default:
                        NSLog("Precise Location not known")
                }
            }
        }

这篇关于iOS 14-当精确的位置权限被拒绝时,如何使iBeacon唤醒应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆