init
This commit is contained in:
47
xhs-mini-demos/component-case/ibeacon/ibeacon.js
Normal file
47
xhs-mini-demos/component-case/ibeacon/ibeacon.js
Normal file
@@ -0,0 +1,47 @@
|
||||
Page({
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: 'iBeacon',
|
||||
path: 'packageAPI/pages/ibeacon/ibeacon',
|
||||
};
|
||||
},
|
||||
|
||||
data: {
|
||||
uuid: '',
|
||||
beacons: [],
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this.stopSearch();
|
||||
},
|
||||
|
||||
enterUuid(e) {
|
||||
this.setData({
|
||||
uuid: e.detail.value,
|
||||
});
|
||||
},
|
||||
|
||||
startSearch() {
|
||||
if (this._searching) return;
|
||||
this._searching = true;
|
||||
xhs.startBeaconDiscovery({
|
||||
uuids: [this.data.uuid],
|
||||
success: res => {
|
||||
console.log(res);
|
||||
xhs.onBeaconUpdate(({ beacons }) => {
|
||||
this.setData({
|
||||
beacons,
|
||||
});
|
||||
});
|
||||
},
|
||||
fail: err => {
|
||||
console.error(err);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
stopSearch() {
|
||||
this._searching = false;
|
||||
xhs.stopBeaconDiscovery();
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user