本項目是用vue嵌套原生混合開發的app,使用H5+api的input標簽調用攝像頭,在瀏覽器上面調用攝像頭是好的,使用hbuilder打包之后就不能正常調用攝像頭
<input type="file" class="capture" capture="camera" @click="clickHandle" id="upload">
解決辦法:給input綁定點擊事件在methods里調用這個clickHandle這個方法利用plus.camera實現iOS的相機調用
clickHandle() { const cmr = window.plus.camera.getCamera(); cmr.captureImage((p) => { window.plus.io.resolveLocalFileSystemURL(p, (entry) => { window.compressImage(entry.toLocalURL(), entry.name); }, (e) => { window.plus.navtiveUI.toast('讀取拍照文件錯誤:' + e.message); }); }, (e) => { console.log(e); }, { filter: 'image' }); },