uniapp分享朋友圈,ios端圖片不顯示
阿新 • • 發佈:2022-05-31
ios分享朋友圈,imageUrl有20kb的大小限制,
前端講圖片下載到本地,然後進行圖片壓縮,就可以顯示了
ios中只允許訪問_www、_doc、_documents、_downloads四個目錄的檔案
uni.downloadFile({ url: shareData.cover, //圖片地址 success: res => { let name=res.tempFilePath.substr(res.tempFilePath.lastIndexOf('/')+1); //擷取檔名 plus.zip.compressImage({ src: res.tempFilePath, //下載完圖片的臨時路徑 dst: '_doc/photoData/'+name, //儲存壓縮完圖片的臨時路徑 overwrite: true, //再次壓縮會覆蓋掉上次的目錄 width:'100px', //縮放圖片的寬度 height:'100px', //縮放圖片的高度 quality:10 //壓縮圖片質量,值越低,圖片佔記憶體越低 }, event => { //壓縮成功 uni.share({ provider: "weixin", scene: "WXSenceTimeline", type: 0, href: app_domain+shareData.path, title: shareData.title, summary: shareData.title, imageUrl: event.target, success: function (res) { uni.showToast({ title:'分享成功', icon:'none', }) }, fail: function (err) { uni.showToast({ title:'分享失敗', icon: 'none' }) } }); }, error => { //壓縮失敗 console.log(error) } } })