无法将 .pkpass 文件下载到 iOS 设备

问题描述 投票:0回答:1

在 iOS 上下载 .pkpass 文件时出现错误:“Safari 无法下载”和“此时无法安装到 Passbook”

const formBody = `paxList=${encodedPayLoad}`;
const response = await fetch(
    "http://192.168.8.154:8080/accelaero/DownloadMobilePass",
    {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: formBody
    });

if (!response.ok) {
    window.alert(response);
    throw new Error("Failed to save pk pass");
}
else {
    const contentDisposition = response.headers.get('Content-Disposition');
    let filename = "pass.pkpass"; // Default filename

    if (contentDisposition && contentDisposition.includes('filename=')) {
        const matches = contentDisposition.match(/filename="?([^";]+)"?/);
        if (matches && matches[1]) {
            filename = matches[1]; // Extracted filename
        }
    }

    const rawBlob = await response.blob();
    const blob = new Blob([rawBlob], { type: 'application/vnd.apple.pkpass' })
    const downloadURL = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = downloadURL;
    a.download = filename;
    document.body.appendChild(a);
    const proceedWithDownload = window.confirm(`Do you want to download the file: ${filename}?`);
    if (proceedWithDownload) {
        a.click();
        window.URL.revokeObjectURL(downloadURL);
        setTimeout(() => {
            a.remove();

        }, 4e4);
    }

此脚本用于使用浏览器在移动设备上下载 .pkpass,但遇到错误。

javascript ios download blob pkpass
1个回答
0
投票

我最近也被同样的问题困扰,并找到了解决方案。

尝试了多种方法,最终找到了解决方案 附上StackOverflow线程,看看吧

有什么方法可以在iPhone上下载多个文件(.pkpass)吗?

© www.soinside.com 2019 - 2024. All rights reserved.