pwa-builder / PWABuilder

The simplest way to create progressive web apps across platforms and devices. Start here. This repo is home to several projects in the PWABuilder family of tools.
https://docs.pwabuilder.com
Other
2.72k stars 280 forks source link

iOS Cannot open file after download #4634

Closed ssugden closed 8 months ago

ssugden commented 8 months ago

What happened?

Our PWA app needs to be able to 'download' a file generated by the app e.g a json file. We have this functionality working for:

However, it does not work for the iOS PWA packaged app built using PWA Builder. The file is generated without issue, but after 'download' nothing happens. Nor can we see the file in the 'Downloads' folder.

Thank you.

How do we reproduce the behavior?

export function download(filename: string, text: string)
{
    let mimeType = "text/plain";
    let periodIndex = filename.indexOf(".");
    if (periodIndex > -1)
    {
        let fileExtension = filename.substring(periodIndex, filename.length).toLowerCase();
        switch (fileExtension)
        {
            case ".json":
                mimeType = "application/json";
                break;
            case ".kml":
                mimeType = "application/vnd.google-earth.kml+xml";
                break;
        }
    }
    var element = document.createElement('a');
    element.setAttribute('href', `data:${mimeType};charset=utf-8,${encodeURIComponent(text)}`);
    element.setAttribute('download', filename);

    element.style.display = 'none';
    document.body.appendChild(element);

    element.click();

    document.body.removeChild(element);
}

What do you expect to happen?

No response

What environment were you using?

OS: iOS

Additional context

No response

Jaylyn-Barbee commented 8 months ago

Hello, we don't offer a ton of support on our GitHub for iOS queries however, we can recommend that you join our Discord community where other developers who have experienced similar issues may be able to answer your question. Click the following link to join: aka.ms/pwabuilderdiscord

ssugden commented 8 months ago

Ok, thanks

nickschinestzki commented 7 months ago

Any updates on this? I'm facing the same problem with my PWA packaged on iOS.

ssugden commented 7 months ago

I still have not found a solution for iOS.

The following is a lightly different approach that I tried but no file is downloaded. Instead, data is displayed on a screen and you cannot navigate back to app. No errors are raised with either approach.

const blob = new Blob([text], { type: mimeType });

const objectUrl = URL.createObjectURL(blob);

const element = document.createElement("a");
element.href = objectUrl;
element.download = filename;
element.click();

URL.revokeObjectURL(objectUrl);
lazmeister commented 4 months ago

here is a thread on the issue https://forums.developer.apple.com/forums/thread/95911