【问题标题】:CoreBluetooth cannot be found when I use my Android device as ibeacon using AltBeacon当我使用我的 Android 设备作为使用 AltBeacon 的 ibeacon 时找不到 CoreBluetooth
【发布时间】:2020-04-20 09:23:19
【问题描述】:

我有使用 CoreBluetooth 的 Ibeacon 扫描应用程序。我想用我真正的安卓设备作为信标。我可以扫描我的 Ibeacon,但找不到我的安卓设备。

import Foundation
import CoreBluetooth 

public class BeaconScanning: NSObject, BKCentralDelegate{
  let central = BKCentral()

  override init(){

    super.init()
    central.delegate = self
    do {
      let serviceUUID = CBUUID(string: "FF80") // For my used Ibeacon Service Data
      let characteristicUUID = CBUUID( )
      let configuration = BKConfiguration(dataServiceUUID: serviceUUID, dataServiceCharacteristicUUID: characteristicUUID)  // Configration for scanning
      try central.startWithConfiguration(configuration)
    } catch let error { }

    central.scanContinuouslyWithChangeHandler({ changes, discoveries in }, stateHandler: { newState in }, duration: 2, inBetweenDelay: 0.1, beaconHandler: { beacons in

      for beacon in beacons! {

         // get beacons properties

      }

    }, errorHandler: { error in })

  }

  public func central(_ central: BKCentral, remotePeripheralDidDisconnect remotePeripheral: BKRemotePeripheral) {

  } 
}

我可以在 IOS 应用中扫描我的 Ibeacon 设备。但是,当我使用我的 Android 设备作为使用 AltBeacon 的 Ibeacon 时找不到它。

Beacon beacon = new Beacon.Builder().  
                .setId1("e2c56db5-dffb-48d2-b060-d0f5a71096e0") //uuid the same my Ibeacon
                .setId2("0") 
                .setId3("0")
                .setManufacturer(0x0118)
                .setTxPower(-59)
                .setDataFields(Arrays.asList(new Long[] {0l}))
                .build();
        BeaconParser beaconParser = new BeaconParser()
                .setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"); //altbeacon layout for parser transmitting as a beacon 
        BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
        beaconTransmitter.startAdvertising(beacon); 

【问题讨论】:

  • 您应该无法使用 CoreBluetooth 找到 Becons,请使用 CoreLocation。因为当 iOS 看到 BLE 设备作为 iBeacon 进行广告宣传时,它不会将其提供给 CoreBluetooth,而是提供给 CoreLocation。
  • @Larme 我可以使用上面给出的 IOS 代码扫描 ibeacons,并使用 CBUUID(string: "FF80") 获取特定时间段内的 RSSI 值。但是当我想扫描 android 设备(充当 ibeacon)时,我不能。
  • 扫描“FF80”不应该让您找到“纯”iBeacon。只有当他们决定宣传它时,您才应该找到设备。也许如果你告诉我们什么是BKConfiguration,因为它似乎能够使用服务 UUID 和特征 UUID(未做广告)进行扫描。
  • @Larme ı 使用 CoreLocation 来查找 android 设备(充当 ibeacon)。 CoreLocation 也可以找到 ibeacon 但找不到 android 设备。但是我的 ıos 设备中的另一个 Locata 应用程序发现我的 android 设备是一个带有 RSSI 的 ibeacon。

标签: android swift core-bluetooth beacon


【解决方案1】:

使用 CoreLocation:

Beacon beacon = new Beacon.Builder()
                .setManufacturer(0x004c) // Use Ibeacon Manufacturer
                .setId1("e2c56db5-dffb-48d2-b060-d0f5a71096e0")
                .setId2("0")
                .setId3("0")
                .setTxPower(-59)
                .setDataFields(Arrays.asList(new Long[] {0l}))
                .build();
        BeaconParser beaconParser = new BeaconParser()
                .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");//BeaconLayout startwith ("m:2-3=0215)
        BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
        beaconTransmitter.startAdvertising(beacon);

【讨论】:

    猜你喜欢
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-08
    • 1970-01-01
    相关资源
    最近更新 更多