uni-app下载文件创建推送,点击推送打开文件

2023-03-23  本文已影响0人  Poppy11

此处需要注意点,调用openFile时,需要创建setTimeout包裹起来,时间最好写一秒,因为发现了,ios是可以正常打开,但是安卓点击推送后是没反应的无法打开。初步推测为安卓打卡openFile需要耗时。

uni.downloadFile({
        url: 'https://mobility-pwa-apac-qa.s3.ap-southeast-1.amazonaws.com/ordersearch/orderSummary_2731473.xls',
        success: (res) => {
            if (res.statusCode === 200) {
                uni.saveFile({
                    tempFilePath: res.tempFilePath,
                    success: function(res) {
                        plus.push.createMessage('download successfully', {
                            downloadFilePath: res.savedFilePath,
                        });
                    }
                });
            } else {
                plus.push.createMessage("Download Fail");
            }
        },
        fail: (err) => {
            console.log("download fail", err)
                plus.push.createMessage("Download Fail");
            }
});

onLoad: function() {
    plus.push.addEventListener('click', (result) => {
        const { payload } = result;
        if (payload?.downloadFilePath) {
            setTimeout(() => {
                plus.runtime.openFile(payload.downloadFilePath, {}, (err) => {
                    console.log("open error", err)
                })
            },1000)
        }
    });
}
上一篇 下一篇

猜你喜欢

热点阅读