|
新开发APP需要后台保持与蓝牙设备通讯,实时获取数据,已按照官方文档配置config.xml
<preference name="backgroundMode" value="audio|bluetooth-peripheral|bluetooth-central"/>
经测试,在安卓设备上运行正常,当程序后台运行/设备锁屏时,均可持续与蓝牙设备连接并获取数据
在IOS设备上,当程序后台运行/设备锁屏时,无法持续获取数据,当重新打开程序,可继续获取数据,IOS版本:11.4.1
循环读取数据代码如下:
setInterval('ble_readValueForCharacteristic()', 2000);
function ble_readValueForCharacteristic(){
ble.readValueForCharacteristic({//setNotify
peripheralUUID: uuid,
serviceUUID: service,
characteristicUUID: characteristicUUID
}, function(ret) {
if (ret) {
console.log(ret.characteristic.value);
$api.byId('sys-info').innerHTML = $api.byId('sys-info').innerHTML + new Date() + hexToString(ret.characteristic.value) + '<br/>';
//api.alert({ msg: JSON.stringify(ret) });
}
});
}
请问IOS要保持程序在后台持续运行还需要进行什么其它配置吗?PS:APP没有正式上线,目前处于测试阶段
|
|