敬告:此 DEMO 演示为开放测试页面,仅用于开发者快速测试体验应用功能,请严格遵守开发者协议,了解更多。
♦ JS-SDK 引用方式:
♦ 普通网页 script 方式加载:下载最新版 jsBridge-v20251019.zip,请在页面上调用 jsBridge 接口之前引用 jsbridge-mini.js 库;
♦ js module 方式引用:npm install ym-jsbridge 具体请参考 npm package
识别结果:
//如果已添加,需移除后再添加
jsBridge.scan({
needResult: true,
//嵌入式扫码
embed: {
//位置,top 或 bottom
//iOS 平台上始终为 top
position: "top",
//高度
height : parseInt($(window).height() * 0.45),
//连续扫码时,两次成功识别之间的最小时间间隔(毫秒),最小 200
interval: 1000
}
}, function(code) {
if (code) {
//震动提示
jsBridge.vibrate();
//处理结果
$("#result").val(code);
}
});
//如果已添加,需移除后再添加
jsBridge.scan({
needResult: true,
embed: {
//iOS 平台上始终为 top
position: "bottom",
height : parseInt($(window).height() * 0.45),
interval: 1000
}
}, function(code) {
if (code) {
//震动提示
jsBridge.vibrate();
//处理结果
$("#result").val(code);
}
});
jsBridge.scan({
embed: {
action: "pause"
}
});
jsBridge.scan({
embed: {
action: "resume"
}
});
jsBridge.scan({
embed: {
//switch light
action: "light"
}
});
jsBridge.scan({
needResult: true,
embed: {
action: "status"
}
}, function(status) {
if (status) {
status = JSON.parse(status);
alert(JSON.stringify(status));
}
});
/*
回调参数 status 是 json 字符串,请转换
{
scanning: boolean //是否正在识别
light : boolean //是否已开启灯光
}
*/
jsBridge.scan({
embed: {
action: "remove"
}
});