在ios9系统上完成正常,升级之后,advertisData转化成字符串 是相同的了(附截图)
代码如下:
else if (app.deviceInnfo.platform == ‘ios’) {
//真机
peripheral = res.devices[0];
var advertisData = peripheral.advertisData;
var data = wx.base64ToArrayBuffer(advertisData);
var str = buf2hex(data);
peripheral.mac_add = getMacAddress(str.toUpperCase());
peripheral.advertisDataStr = str;
array.push(res.devices[0]);
console.log(peripheral);
}
function buf2hex(buffer) {
return Array.prototype.map.call(new Uint8Array(buffer), x => (‘00’ + x.toString(16)).slice(-2)).join(’’);
}
var advertisData = tempDevice[0].advertisData
//var data = wx.arrayBufferToBase64(advertisData)
var str = that.buf2hex(advertisData)
console.log(tempDevice[0].deviceId, ‘============’, data)
这里打印出来的data为:ABvGqhgLJd7rxxyLhwPGV+MB672BlqiW
和mac地址有关?
@蔷薇
这里共性问题是开发者将获取到的arrayBuffer执行了一次 base64ToArrayBuffer ,就会出现字符串一致的情况
var advertisData = peripheral.advertisData;
var data = wx.base64ToArrayBuffer(advertisData);
应该执行的是 wx.arrayBufferToBase64,才能获取到arrayBuffer的base64字符串,如果你的advertisData只是Mac地址的话,也可以按上述的开发者解决方案来做
function buf2hex(buffer) {
return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');