简体   繁体   English

如何在 ios 设备上检测独特的 ibeacon 广告 react-native?

[英]how to detect unique ibeacon advertisements react-native on ios device?

I have IoT devices (emergency watch) which sends iBeacon advertisements when button on device is triggered and i am detecting these signals on my react-native application.我有物联网设备(紧急手表),当设备上的按钮被触发时,它会发送 iBeacon 广告,并且我在我的 react-native 应用程序上检测到这些信号。

The problem i am facing is differentiating which signal belongs to which IoT device.我面临的问题是区分哪个信号属于哪个物联网设备。

I am currently using kontakio react-native library.我目前正在使用kontakio react-native 库。 On iOS the library does not fetch the MAC address of the beacon.在 iOS 上,库不获取信标的 MAC 地址。 On the android it fetches the MAC address of the beacon devices.在 android 上,它获取信标设备的 MAC 地址。

The idea is to render these on list and when user selects one it will be stored in the phones memory and only look at the emergency call from that particular mac address.这个想法是在列表中呈现这些,当用户选择一个时,它将存储在手机 memory 中,并且只查看来自该特定 mac 地址的紧急呼叫。

Here is the code logic so far:到目前为止的代码逻辑如下:

    if (isAndroid) {
  DeviceEventEmitter.addListener(
    'beaconsDidUpdate',
    async ({beacons, region}) => {
      const pairedBeacon = await getDataFromStorage();
      beacons.map(b => {
        if (
          b.proximity == 'IMMEDIATE' ||
          b.proximity == 'NEAR' 
        ) {
          setList(beacons);
        }
        if (b.address == pairedBeacon) {
          emergencyCall();
        }
      });
    },
  );

} else {
  kontaktEmitter.addListener(
    'didRangeBeacons',
    async ({beacons, region}) => {
      beacons.map(b => {
        if (
          b.proximity == 'immediate' ||
          b.proximity == 'near'
        ) {
          setList(beacons);
        }
      });
    },
  );

Any idea on how i can solve this on the iOS side?关于如何在 iOS 方面解决这个问题的任何想法? Help is greatly appreciated.非常感谢您的帮助。

The best solution is to configure the IoT device to send out a unique beacon identifier for each device, so that you can rely on the beacon identifier rather than the MAC address.最好的解决方案是配置物联网设备为每个设备发送一个唯一的信标标识符,这样您就可以依赖信标标识符而不是 MAC 地址。 This is true regardless of whether you use Eddystone or iBeacon advertisements because:无论您使用 Eddystone 还是 iBeacon 广告都是如此,因为:

  1. iOS provides no access to identifiers for iBeacon advertisements besides the beacon UUID/major/minor.除了信标 UUID/major/minor 之外,iOS 不提供对 iBeacon 广告标识符的访问。 It does not provide access to the MAC.它不提供对 MAC 的访问。
  2. iOS provides no access to the MAC for Eddystone advertisements -- it only gives access to the beacon namespace and instance ID, plus a "peripheral id" which is a 32-bit UUID mapped internally by iOS to the Bluetooth MAC address. iOS 不提供对 Eddystone 广告 MAC 的访问权限——它只提供对信标命名空间和实例 ID 的访问权限,以及一个“外围 id”,这是一个由 iOS 内部映射到蓝牙 MAC 地址的 32 位 UUID。 There is no way to determine the actual MAC from the peripheral id.无法从外设 id 确定实际的 MAC。

The above restrictions are true regardless of whether you are using React Native or the library from Kontakt.io.无论您使用的是 React Native 还是 Kontakt.io 中的库,上述限制都是正确的。 It is an operating system restriction.这是一个操作系统限制。

If you cannot change the beacon identifiers on your IoT device for some reason, then you might be able to establish a bluetooth connection to the device and query it for its MAC address or other unique identifier.如果由于某种原因您无法更改 IoT 设备上的信标标识符,那么您可以建立与设备的蓝牙连接并查询其 MAC 地址或其他唯一标识符。 The Eddystone advertisement will allow you to get access to the "peripheral id" needed to establish the connection to do this. Eddystone 广告将允许您访问建立连接以执行此操作所需的“外围设备 ID”。 However, for this to work, the IoT device must support connections (beacons are typically not connectable, but may support connections in some modes) and must expose access to the MAC or other unique identifier in a readable characteristic.但是,要使其工作,物联网设备必须支持连接(信标通常不可连接,但可能支持某些模式下的连接),并且必须公开对 MAC 或其他可读特征中的唯一标识符的访问。 It is conceivable that the IoT hardware supports this, but it is far from certain.可以想象物联网硬件支持这一点,但还不确定。 You need to check the hardware documentation to see what you can do, or you need to control the IoT device firmware to make it do what you need.您需要查看硬件文档以了解您可以做什么,或者您需要控制 IoT 设备固件以使其执行您需要的操作。

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

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