简体   繁体   English

iOS仍然可以在iOS 10中的iBeacon范围内启动应用程序吗?

[英]Can iOS still launch an app in range of iBeacon in iOS 10?

I have been searching for days now on this subject. 我一直在寻找有关该主题的天。 I have seen a few posts but none of the implementations work, or, they mention deprecated methods, options or Libraries that are private. 我看过几篇文章,但所有实现都不起作用,或者,他们提到了不推荐使用的方法,选项或私有库。 I find Apple docs to be the worst thing of all time and yet even in that debacle wall of text known as their docs I found a few references to launching a terminated application based on entering the range of an iBeacon. 我发现Apple文档是有史以来最糟糕的事情,但是即使在那被称为文档的文本混乱墙中,我也发现了一些参考,它们基于输入iBeacon的范围来启动终止的应用程序。

What I need is to have the app be fully closed and terminated as though the user is completed and finished with it. 我需要做的是完全关闭并终止该应用程序,就像用户已完成并完成该操作一样。 Then I need to use the UIBackgroundMode for BLE services in info.plist for listening to the didRangeBeacons delegate method. 然后,我需要在info.plist中将UIBackgroundMode用于BLE服务,以侦听didRangeBeacons委托方法。 It fires, so I know that much is working. 它会触发,所以我知道很多工作。

It's at this point that all implementations so far have failed. 到目前为止,到目前为止所有实现都失败了。 How on earth do you launch the app to even a backgrounded state from being in range of an iBeacon? 您究竟如何将应用程序从iBeacon范围内启动到甚至是背景状态? I am beginning to think all you can do is trigger a local notification when in range... 我开始认为您所能做的就是在范围内触发本地通知...

Getting an app to auto-launch from a not-running state based on iBeacon detection is surprisingly easy with CoreLocation and iBeacon. 借助CoreLocation和iBeacon, CoreLocation基于iBeacon检测的应用程序从未运行状态自动启动非常容易。

In order for it to work a few pre-requisites must be met: 为了使其正常工作,必须满足一些先决条件:

  1. The app must have been manually launched once before. 该应用程序必须已经手动启动过一次。
  2. The app must request and obtain "Always" location access from the user on first launch. 该应用必须在首次启动时向用户请求并获得“始终”位置访问权限。
  3. The app must register a CLBeaconRegion with CLLocationManager by calling locationManager.startMonitoring(region: region) , and set the locationManager.delegate . 应用必须通过调用locationManager.startMonitoring(region: region)CLLocationManager注册CLBeaconRegion ,并设置locationManager.delegate Since you also want to range, you can simultaneously call startRanging(beacons: beacons, region: region) . 由于您还想进行范围调整,因此可以同时调用startRanging(beacons: beacons, region: region) It is usually easiest to do this in your AppDelegate. 通常最简单的方法是在AppDelegate.执行此操作AppDelegate.
  4. The phone must have location enabled and bluetooth turned on. 手机必须启用了位置并打开了蓝牙。

If you do all of the above correctly, then iOS CoreLocation will remember that your app has registered the CLBeaconRegion and auto launch your app on beacon detection. 如果您正确执行上述所有操作,则iOS CoreLocation会记住您的应用已注册CLBeaconRegion并在检测到信标时自动启动您的应用。 Even if you reboot the phone, or kill your app from the task switcher it will do this. 即使重新启动手机,或从任务切换器中杀死应用程序,它也会这样做。 After auto launching your app into the background, it will call the didEnter(region: region) callback on your delegate and then start calling the didRange(beacons: beacons, region: region) callback once per second for about 10 seconds, until the operating system will once again suspend your app. 在后台自动启动您的应用程序后,它将在委托上调用didEnter(region: region)回调,然后开始每秒调用一次didRange(beacons: beacons, region: region)回调,持续约10秒钟,直到运行系统将再次暂停您的应用。

There are lots of ways to make mistakes when testing so this doesn't work. 有很多方法可以在测试时出错,所以这是行不通的。 But if you do everything right, this is pretty darn reliable. 但是,如果您做对了所有事情,这是相当可靠的。

What you can't do is bring the app to the foreground programmatically, because iOS does not allow this. 您不能做的是以编程方式将应用程序置于前台,因为iOS不允许这样做。 On iOS, a user must gesture to bring an app to the foreground -- this is nothing to do with beacons, but a long-standing rule in the design of the OS. 在iOS上,用户必须打手势将应用程序置于前台–这与信标无关,但在OS设计中却是一个长期的规则。 This is why many apps send a local notification while they are in this brief background state after detecting a beacon to give the user a way to bring the app to the foreground. 这就是为什么许多应用程序在检测到信标后处于短暂的后台状态时会发送本地通知的原因,从而为用户提供了一种将应用程序置于前台的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM