Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView analog of service worker

I'm trying to implement part of app with PWA approach, that works fine on Android, but not for iOS. We need to have

  • offline content availability
  • option to update content dynamically (like special offers or so). With service worker we show prompt to update web content.

As were mentioned here service workers are not supported within WKWebView (or UIWebView). So is there analog or alternative solution like smart cache control?

Seems like it is possible to store some web content from app and be able to update it if something changes. May there is already a framework/library/approach for that purpose?

EDIT Service Workers unavailable in WKWebView in iOS 11.3 - this question explains the status of ServiceWorkers in WKWebView, but no alternative is given. I would like to discuss any alternative solutions.

One thing I discovered is https://github.com/xtools-at/iOS-PWA-Wrapper. It looks like working based on AppCache, but https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache#Browser_compatibility says it is deprecated and adviced to use SW instead (which is not an option for PWA).

like image 203
SimB4 Avatar asked Mar 12 '19 10:03

SimB4


People also ask

Does WKWebView support service workers?

Description. Since iOS14, it's possible to make service workers works in WKWebView by providing a list of trusted domains (up to 10). These domains then gain support for service workers, which is invaluable for us as we plan to use server.

What is a WKWebView?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

What browser does WKWebView use?

WKWebView uses the Nitro JavaScript engine, also used by mobile Safari, which comes with significant performance improvements over UIWebView's older JavaScript engine.

Is WKWebView secure?

The WKWebView is a modern API applying all the modern web security mechanisms, it's still maintained by Apple and gets updates. The good thing about WKWebView is that it does out-of-process rendering, so if the attackers find a memory corruption vulnerability in it, your application's process is still isolated.


1 Answers

So before WKWebView get service-workers to work, you can use AppCache (not yet fully deprecated). You can use this and take a look at source page at https://leasingrechnen.at What they do? In case if there is no service worker in browser, they load iframe that points to a page with manifest.appcache file implemented, so the page is cached.

like image 189
SimB4 Avatar answered Sep 28 '22 12:09

SimB4