ibeacon.js 752 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: 'iBeacon',
  5. path: 'page/API/pages/ibeacon/ibeacon'
  6. }
  7. },
  8. data: {
  9. uuid: '',
  10. beacons: []
  11. },
  12. onUnload() {
  13. this.stopSearch()
  14. },
  15. enterUuid(e) {
  16. this.setData({
  17. uuid: e.detail.value
  18. })
  19. },
  20. startSearch() {
  21. if (this._searching) return
  22. this._searching = true
  23. wx.startBeaconDiscovery({
  24. uuids: [this.data.uuid],
  25. success: (res) => {
  26. console.log(res)
  27. wx.onBeaconUpdate(({beacons}) => {
  28. this.setData({
  29. beacons
  30. })
  31. })
  32. },
  33. fail: (err) => {
  34. console.error(err)
  35. }
  36. })
  37. },
  38. stopSearch() {
  39. this._searching = false
  40. wx.stopBeaconDiscovery()
  41. }
  42. })