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.55k stars 273 forks source link

[BUG] Offline mode not working on iPhone #4649

Closed JuanCecenasJPGlobal closed 5 months ago

JuanCecenasJPGlobal commented 5 months ago

What happened?

We have an application with a feature that can be used offline (our PWA was tested and works offline on the web and Android, the problem is on iPhone).

The issue is that when we are offline and open the application, it shows us a screen with the application icon and the disconnected wifi icon, and it does not allow us to navigate. We identified where that code was (viewController, func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)) and slightly modified it to allow us to view the content.

The problem now is that the content does not seem to be cached, and it shows us an error screen, and in the console, we see "Navigation failed with error: A server with the specified hostname could not be found."

If we install the PWA within the same Xcode simulator, it works offline, but it does not when we run the application generated with PWABuilder.

Does offline mode works on iPhone? How?

How do we reproduce the behavior?

On iPhone turn on Airplane mode

What do you expect to happen?

No response

What environment were you using?

iPhone 15 Pro Max

Additional context

No response

khmyznikov commented 5 months ago

@JuanCecenasJPGlobal activate the debug mode and try to inspect your cache storage. Which iOS version?

JuanCecenasJPGlobal commented 5 months ago

@khmyznikov I've activated debug mode and have been inspecting the cache storage. Currently, I can see and access the Indexed DB, however, I'm not observing that the files are being cached. It seems like the application always attempts to fetch files from the server instead of utilizing the local cache. Could you provide guidance on how to address this issue? Additionally, the iOS version I'm conducting these tests on is 17.2

hoveit commented 5 months ago

Same issue here!

JuanCecenasJPGlobal commented 5 months ago

Additionally, I came across some information suggesting that using reload or reloadFromOrigin instead of load might have an impact on caching. Could you confirm if this could be relevant to our issue?

Furthermore, I found some resources discussing how to activate cache mode in Swift. However, I'm unsure about how to implement or configure it in our app. Would enabling cache mode or implementing any specific steps help in ensuring the correct offline functionality of our application? It's worth mentioning again that the PWA works offline seamlessly on web and Android platforms.

JuanCecenasJPGlobal commented 5 months ago

Additionally, I came across a code snippet that uses navigator.storage.persist() to attempt to persist local storage in the browser. Although I've tried implementing it in my sw.js file, I receive an error message indicating that persist is not a valid function.

navigator.storage.persist().then(function(persistent) { if (persistent) console.log("Storage will not be cleared except by explicit user action"); else console.log("Storage may be cleared by the UA under storage pressure."); });

While I haven't been able to get it working yet, I thought it might be helpful to mention it here in case it provides any clues on how to address our caching issue in the iOS app.

jgw96 commented 5 months ago

Hello all!

I am going to ask that we move this discussion to our Discord https://aka.ms/pwabuilderdiscord as that is where we normally handle issues for our experimental iOS platform. Thanks all!