小程序详情页浏览量如何实现

小程序详情页浏览量如何实现,第1张

对于小程序的浏览量,也是跟app差不多的,要在于推广,只有推广好,小程序才会有更多的浏览器以及关注度,那么如何对小程序进行推广呢,就目前来说,可以结合线上、线下进行,比如线上可以:

1、附近的小程序入口。

附近小程序基于LBS的门店位置的推广,会自然带来访问量,为门店带来有效客户。

2、微信搜索进入。

小程序可以在微信搜索里直接进入,拥有线上的搜索流量。

3、长按识别小程序二维码进入。

4、小程序的参数二维码,可以利用积分宝海报形式进行线上运营传播。

5、微信图文可以插入小程序,也是小程序推广运营的重要方式,而且结合微信图文, 借助微信小程序的直接引导,提高线上转化率。

6、自媒体平台软文推广。

7、转发分享。

8、公众号关联小程序,利用公众号积累的影响力。

9、公众号资料页展示小程序也是小程序的重要入口之一,能为小程序带来自然的用户 。

线下:

1、小程序二维码推广。

2、圆形小程序码推广。

3、扫描普通二维码进入小程序。

4、门店、宣传海报、广告栏带小程序相关二维码。

5、线下扫码、地推。

#使用mpvue 开发小程序过程中 简单介绍一下微信小程序蓝牙连接过程

#在蓝牙连接的过程中部分api需要加定时器延时1秒到2秒左右再执行,原因为何不知道,小程序有这样的要求

#1首先是要初始化蓝牙:openBluetoothAdapter()

```js

if (wxopenBluetoothAdapter) {

wxopenBluetoothAdapter({

        success: function(res) {

            / 获取本机的蓝牙状态 /

            setTimeout(() => {

                getBluetoothAdapterState()

            }, 1000)

        },

        fail: function(err) {

            // 初始化失败

        }

    })

    } else {    

    }

```

#2检测本机蓝牙是否可用:

#  要在上述的初始化蓝牙成功之后回调里调用

```js

getBluetoothAdapterState() {

    var that= this;

    thattoastTitle= '检查蓝牙状态'

wxgetBluetoothAdapterState({

        success: function(res) {

startBluetoothDevicesDiscovery()

},

        fail(res) {

            consolelog(res)

}

})

}

```

#3 开始搜索蓝牙设备

```js

startBluetoothDevicesDiscovery() {

    var that= this;

    setTimeout(() => {

wxstartBluetoothDevicesDiscovery({

            success: function(res) {

/ 获取蓝牙设备列表 /

                thatgetBluetoothDevices()

},

            fail(res) {

}

})

}, 1000)

}

```

#4 获取搜索到的蓝牙设备列表

# / thatdeviceName 是获取到的蓝牙设备的名称, 因为蓝牙设备在安卓和苹果手机上搜到的蓝牙地址显示是不一样的,所以根据设备名称匹配蓝牙/

```js

getBluetoothDevices() {

    var that= this;

    setTimeout(() => {

wxgetBluetoothDevices({

            services: [],

            allowDuplicatesKey: false,

            interval: 0,

            success: function(res) {

                if (resdeviceslength> 0) {

                    if (JSONstringify(resdevices)indexOf(thatdeviceName) !== -1) {

                        for (let i = 0; i < resdeviceslength; i++) {

                            if (thatdeviceName === resdevices[i]name) {

/ 根据指定的蓝牙设备名称匹配到deviceId /

                                thatdeviceId = thatdevices[i]deviceId;

                                setTimeout(() => {

                                    thatconnectTO();

}, 2000);

};

};

} else {

}

} else {

}

},

            fail(res) {

                consolelog(res, '获取蓝牙设备列表失败=====')

}

})

}, 2000)

},

```

#5连接蓝牙

# 匹配到的蓝牙设备ID 发送连接蓝牙的请求, 连接成功之后 应该断开蓝牙搜索的api,然后去获取所连接蓝牙设备的service服务

```js

connectTO() {

wxcreateBLEConnection({

        deviceId: deviceId,

        success: function(res) {

            thatconnectedDeviceId = deviceId;

/ 4获取连接设备的service服务 /

thatgetBLEDeviceServices();

wxstopBluetoothDevicesDiscovery({

                success: function(res) {

                    consolelog(res, '停止搜索')

},

                fail(res) {

}

})

},

        fail: function(res) {

}

})

}

```

#6 获取蓝牙设备的service服务,获取的serviceId有多个要试着连接最终确定哪个是稳定版本的service 获取服务完后获取设备特征值

```js

getBLEDeviceServices() {

    setTimeout(() => {

wxgetBLEDeviceServices({

            deviceId: thatconnectedDeviceId,

            success: function(res) {

                thatservices= resservices

/ 获取连接设备的所有特征值 /

thatgetBLEDeviceCharacteristics()

},

            fail: (res) => {

}

})

}, 2000)

},

```

#7获取蓝牙设备特征值

# 获取到的特征值有多个,最后要用的事能读,能写,能监听的那个值的uuid作为特征值id,

```js

getBLEDeviceCharacteristics() {

            setTimeout(() => {

wxgetBLEDeviceCharacteristics({

                    deviceId: connectedDeviceId,

                    serviceId: services[2]uuid,

                    success: function(res) {

                        for (var i = 0; i < rescharacteristicslength; i++) {

                            if ((rescharacteristics[i]propertiesnotify || rescharacteristics[i]propertiesindicate) &&

                                (rescharacteristics[i]propertiesread && rescharacteristics[i]propertieswrite)) {

                                consolelog(rescharacteristics[i]uuid, '蓝牙特征值 ==========')

/ 获取蓝牙特征值 /

                                thatnotifyCharacteristicsId = rescharacteristics[i]uuid

// 启用低功耗蓝牙设备特征值变化时的 notify 功能

thatnotifyBLECharacteristicValueChange()

}

}

},

                    fail: function(res) {

}

})

}, 1000)

},

```

#8启动notify 蓝牙监听功能 然后使用 wxonBLECharacteristicValueChange用来监听蓝牙设备传递数据

#接收到的数据和发送的数据必须是二级制数据, 页面展示的时候需要进行转换

```js

notifyBLECharacteristicValueChange() { // 启用低功耗蓝牙设备特征值变化时的 notify 功能

            var that= this;

            consolelog('6启用低功耗蓝牙设备特征值变化时的 notify 功能')

wxnotifyBLECharacteristicValueChange({

                state: true,

                deviceId: thatconnectedDeviceId,

                serviceId: thatnotifyServicweId,

                characteristicId: thatnotifyCharacteristicsId,

                complete(res) {

/用来监听手机蓝牙设备的数据变化/

wxonBLECharacteristicValueChange(function(res) {

//

                        thatbalanceData += thatbuf2string(resvalue)

                        thathexstr += thatreceiveData(resvalue)

})

},

                fail(res) {

                    consolelog(res, '启用低功耗蓝牙设备监听失败')

                    thatmeasuringTip(res)

}

})

},

/转换成需要的格式/

buf2string(buffer) {

                    var arr = Arrayprototypemapcall(new Uint8Array(buffer), x => x)

                    return arrmap((char, i) => {

                        return StringfromCharCode(char);

                    })join('');

},

receiveData(buf) {

return thishexCharCodeToStr(thisab2hex(buf))

},

/转成二进制/

ab2hex (buffer) {

              var hexArr = Arrayprototypemapcall(

                  new Uint8Array(buffer), function (bit) {

                      return ('00' + bittoString(16))slice(-2)

}

)

              return hexArrjoin('')

},

/转成可展会的文字/

hexCharCodeToStr(hexCharCodeStr) {

              var trimedStr = hexCharCodeStrtrim();

              var rawStr = trimedStrsubstr(0, 2)toLowerCase() === '0x' trimedStrsubstr(2) : trimedStr;

              var len = rawStrlength;

              var curCharCode;

              var resultStr= [];

              for (var i = 0; i < len; i = i+ 2) {

                  curCharCode = parseInt(rawStrsubstr(i, 2), 16);

                  resultStrpush(StringfromCharCode(curCharCode));

}

              return resultStrjoin('');

},

```

# 向蓝牙设备发送数据

```js

sendData(str) {

    let that= this;

    let dataBuffer = new ArrayBuffer(strlength)

    let dataView = new DataView(dataBuffer)

    for (var i = 0; i < strlength; i++) {

        dataViewsetUint8(i, strcharAt(i)charCodeAt())

}

    let dataHex = thatab2hex(dataBuffer);

    thiswriteDatas = thathexCharCodeToStr(dataHex);

wxwriteBLECharacteristicValue({

        deviceId: thatconnectedDeviceId,

        serviceId: thatnotifyServicweId,

        characteristicId: thatnotifyCharacteristicsId,

        value: dataBuffer,

        success: function (res) {

            consolelog('发送的数据:' + thatwriteDatas)

            consolelog('message发送成功')

},

        fail: function (res) {

},

        complete: function (res) {

}

})

},

```

# 当不需要连接蓝牙了后就要关闭蓝牙,并关闭蓝牙模块

```js

// 断开设备连接

closeConnect() {

if (thatconnectedDeviceId) {

wxcloseBLEConnection({

            deviceId: thatconnectedDeviceId,

            success: function(res) {

thatcloseBluetoothAdapter()

},

            fail(res) {

}

})

} else {

thatcloseBluetoothAdapter()

}

},

// 关闭蓝牙模块

closeBluetoothAdapter() {

wxcloseBluetoothAdapter({

        success: function(res) {

},

        fail: function(err) {

}

})

},

```

#在向蓝牙设备传递数据和接收数据的过程中,并未使用到read的API 不知道有没有潜在的问题,目前线上运行为发现任何的问题

#今天的蓝牙使用心得到此结束,谢谢

setTimeout中函数内的this是指向了window对象,setInterval同理

如果想要让setTimeout中的this不指向window,可以使用以下常用办法:

方法一:使用之前重新指向到一个变量,然后 *** 作这个新的变量

微信小程序中经常见到重新定义this的指向that,之后 *** 作that

方法二:

使用ES6的箭头函数

Systemoutprintln(calget(CalendarMONDAY)+1+"月"+(calget(CalendarDAY_OF_MONTH)+1)+"日"); //输出日期

以上就是关于小程序详情页浏览量如何实现全部的内容,包括:小程序详情页浏览量如何实现、微信小程序蓝牙教程--完整版亲测、setTimeout中this指向的问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10123690.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存