21

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?

Anand
  • 9,672
  • 4
  • 55
  • 75
kochizufan
  • 2,120
  • 2
  • 30
  • 50

2 Answers2

22

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.

Anand
  • 9,672
  • 4
  • 55
  • 75
  • 1
    If we want to restart the app when it is start as normal (clicking on app icon) but keeping the state when it is brought back from background, is there any way to distinguish this two action? – Red Bit Oct 16 '18 at 09:42
  • 1
    The issue was fixed with ios version 12.2 beta 2 – leox Mar 12 '19 at 10:51
  • I'm wondering if this is the same problem I'm noticing here https://stackoverflow.com/questions/58274674/web-app-auto-redirecting-to-the-initial-page-on-ios-problem-it-should-not-redir. After a few seconds of inactivity, the app reloads the initial page. – Pablo Cantero Oct 07 '19 at 18:58
  • this seems to be a problem for me on android as well :/ any suggestions? the app resets and lands on the sign in page if i switch apps on android 8-9 – Paulo Feb 04 '20 at 08:15
6

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!

Roshil K
  • 2,583
  • 28
  • 38
  • 1
    I came across this answer a week ago when this was the case and now that I've updated to iOS 12.2, the app's state persists. You get the splash page every time it opens but it's where you left it on my very basic project. – cchana Mar 26 '19 at 14:14