Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PWA Application is initialized every time after going background in iOS

I'm now testing PWA application.

In Android, it works well. Even after going background, PWA app keep condition and user can continue their experience.

But in iOS, every time after PWA app goes background, it is initialized and every condition is crushed like it is reloaded. User experience is terminated.

How can I prevent this in iOS?

like image 365
kochizufan Avatar asked Mar 31 '18 10:03

kochizufan


People also ask

Can a PWA run in the background?

Using a service worker, a Progressive Web App (PWA) can do work in the background, even when the user isn't using the app. Service workers used to be reserved for native apps, but they are now also available to PWAs, providing a better offline experience.

Do progressive Web Apps work on iOS?

You can use Progressive Web Apps (PWAs) for a fast web experience on your computer or mobile device. You can install the PWA for faster access and additional functionality, like more storage for content to use offline. Chrome for iOS does not support PWAs.

How do I know if PWA is installed on iOS?

navigator. standalone === true; That way, you know if they're an iOS user who can potentially install your PWA or not, and if they've opened your PWA from the home screen. If the user opens your PWA in the browser, unfortunately there is no way to check if it's already been installed.


2 Answers

Update : With the latest version of iOS(I've tested with 12.4), PWA state is preserved. Thanks to Leox and Roshil on confirming the same with another version.

Original answer to handle older version of iOS/Safari :

As mentioned in this article, iOS still doesn't preserve the state of a PWA app between sessions :( Since the first official support for service workers came just a week before(Late March-2018) in iOS, we can expect to see more features such as preserving the state in the future .

We are out of luck for now.

You can also see "What PWAs can do on Android and not on iOS" section in the linked article on current gaps between android and iOS with respect to PWA.

As a workaround, you can keep persisting the state of your application(current page, user filled data, scroll start if possible) in IndexDB and when the application is reopened you can read that to restore it. It works for pretty much most use cases.

like image 174
Anand Avatar answered Oct 07 '22 16:10

Anand


Now you can update your iOS to 12.2 beta 5 to hold the state of the PWA app after restored it from minimized state. Thanks to Apple!

like image 29
Roshil K Avatar answered Oct 07 '22 16:10

Roshil K