uniapp搜索附近蓝牙信标(iBeacon)

一、 iBeacon介绍

iBeacon是苹果在2013年WWDC上推出一项基于蓝牙4.0(Bluetooth LE | BLE | Bluetooth Smart)的精准微定位技术,在iPhone 4S后支持。当你的手持设备靠近一个Beacon基站时,设备就能够感应到Beacon信号,范围可以从几毫米到50米。因为是一种定位技术,苹果将iBeacon相关的接口放到了 CoreLocation.framework。Google在Android 4.3及后续版本支持了该功能,只要满足iBeacon技术标准即可。iBeacon底层的技术使用的使用BLE(Bluetooth Low Energy)。

二、技术文档

参考:lBeacon API

三、代码实现

//开始搜索蓝牙设备
startDiscoverBluetooth() {
   
	let that = this;
	//蓝牙初始化
	uni.openBluetoothAdapter({
    
		success(res) {
   
			uni.getLocation({
   
				success(res) {
   
					//开始搜索蓝牙设备
					uni.startBeaconDiscovery({
   
						success(res) {
   
							uni.onBeaconUpdate((res) => {
   
								console.log("设备信息=> ", res)
							})
						}, fail(res) {
   
							console.log('搜索蓝牙设备失败!', res);
						}
					})
				}, fail(res) {
   
					uni.showModal({
   
						title:'提示',
						content:'请打开位置,并下拉刷新!',
						confirmText:'好的',
						showCancel:false,
					})
				}
			})
		}, fail(res) {
   
			uni.showModal({
   
				title:'提示',
				content:'请打开蓝牙,并下拉刷新!',
				confirmText:'好的',
				showCancel:false,
			})
		}
	})
},

四、小结

目前只能在手机处于亮屏状态下(包括软件在后台运行)才能监测到周围的信标设备,熄屏状态下监测不到(目前还未解决),如有解决的,欢迎大神留言讨论!

相关推荐

  1. uniapp搜索附近iBeacon

    2024-01-13 14:56:01       38 阅读
  2. uniapp

    2024-01-13 14:56:01       37 阅读
  3. uniapp 小程序

    2024-01-13 14:56:01       39 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-13 14:56:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-13 14:56:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-13 14:56:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-13 14:56:01       18 阅读

热门阅读

  1. SQL常用时间处理函数总结

    2024-01-13 14:56:01       38 阅读
  2. RNN和LSTM的区别是什么?

    2024-01-13 14:56:01       33 阅读
  3. 利用PowerShell和Mkvtoolnix批量去除视频封面

    2024-01-13 14:56:01       41 阅读
  4. 深入理解虚拟DOM:原理、优势与实践

    2024-01-13 14:56:01       28 阅读
  5. 一文读懂Qt信号与槽的机制

    2024-01-13 14:56:01       31 阅读
  6. 传统的背包问题~3479:【例86.4】 混合背包

    2024-01-13 14:56:01       35 阅读