android - iOS CLLocationManager 未检测到从 Android 发送的 Android 信标库 iBeacon 信号
问题描述
应用目的
- 从 iOS 传输 Beacon 信号并在 Android 和 iOS 设备上检测该信号。
- 从 Android 传输 Beacon 信号并在 Android 和 iOS 设备上检测该信号。
技术
Android:Android 信标库。
- 在 Android 设备之间发送和接收 AltBeacon 信号(以获得更好的准确性)
- 从 iOS 发送并在 Android 上接收的 iBeacon 信号
- 从 Android 发送并在 iOS 上接收的 iBeacon 信号(不工作)
iOS:CoreLocation CLLocationManager iBeacon。
- 从 iOS 发送并在 iOS 上接收的 iBeacon 信号
- 从 iOS 发送并在 Android 上接收的 iBeacon 信号
- 从 Android 发送并在 iOS 上接收的 iBeacon 信号(不工作)
问题
- 在两个平台上使用相同的 UUID,当从 iOS 传输 iBeacon 信号时,它会在另一个 iOS 设备上使用 CLLocationManager 委托方法检测到
locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion)
使用相同的 UUID 通过 Android 信标库从 Android 传输 iBeacon 信号,iOS 上的上述 CLLocationManager 委托方法未检测到信标。
编码
- 为了增加检测的机会,我在 iOS 端去掉了对 Major 和 Minor 值的要求,以防止 iOS 因 Major 和 Minor 值不匹配而过滤掉 Beacon 信号的可能性。
- 是的,我尝试添加主要和次要值无济于事。
- 我也尝试过使用以下方法对信标进行测距:
func startRangingBeacons(satisfying constraint: CLBeaconIdentityConstraint)
在 iOS 上检测
var locationManager: CLLocationManager!
var localBeaconUUID = "578f4eba-a16e-11ea-bb37-0242ac130002"
let beaconIdentifier = "MyBeacon"
override func viewDidLoad() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
}
func startScanning() {
let uuid = UUID(uuidString: localBeaconUUID)!
let beaconRegion = CLBeaconRegion(uuid: uuid, identifier: beaconIdentifier)
locationManager.startMonitoring(for: beaconRegion)
locationManager.startRangingBeacons(in: beaconRegion)
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
print("Ranged beacons: \(beacons.count)")
}
在 Android 上传输 iBeacon
private val uuid = "578f4eba-a16e-11ea-bb37-0242ac130002"
fun transmitBeacon() {
val beacon = Beacon.Builder()
.setId1(uuid)
.setId2("1")
.setId3("1")
.setManufacturer(0x004c)
.setTxPower(-59)
.setDataFields(listOf(0L))
.build()
val beaconParser = BeaconParser()
.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24")
val beaconTransmitter = BeaconTransmitter(applicationContext, beaconParser)
beaconTransmitter.startAdvertising(beacon)
}
解决方案
此处显示的布局:
val beaconParser = BeaconParser()
.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24")
用于 AltBeacon,iOS 设备无法通过 CoreBluetooth 检测到。您只能使用该 iOS API 来检测具有以下布局的 iBeacon:
val beaconParser = BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")
在另一个论坛的较早答案中,我注意到 OP 正在使用添加了数据字段的布局并建议他将其删除,但没有意识到问题中的布局使用beac
仅有效的匹配字节的更根本问题用于 AltBeacon 格式。对于 iBeacon,您必须匹配0215
推荐阅读
- python-3.x - 使用 python 使用 import xml.etree.ElementTree 将 XML 解析为 CSV
- javascript - 使用 useReducer 和 useContext,当一个动作被调度时,组件不会被重新渲染。如何触发重新渲染?
- mongodb - rand 字符串作为自定义 _id 会使 B 树索引在 MongoDB 中分裂的频率更高吗?
- trackpy - trackpy中的粒子跟踪算法
- ios - 如何检测 SpriteKit 游戏是否移至后台(该人退出应用程序)
- php - Laravel:使用分页和排序的http方法出错
- sql - 具有多个条件的 SQL Where 条件
- python - sys.argv / cmd中的python特殊符号
- python - 跨多列非数字数据制作数据透视表
- c++ - 如何显示选择的变量?