18.3 C
New York
Thursday, November 7, 2024

javascript – How you can load WKWebView and not using a view (iOS)


I must run WKWebView in a number of contexts, together with ones the place there isn’t any view.

Within the App, it is wonderful. Load it, hyperlink it, present it.
However I additionally must load it in a widget – not for show, however to entry the info saved within the indexeddb on the web page, additionally for a background processing process (although that is much less crucial), and eventually within the handler for a pushed notification.
The difficulty right here is I do not need to transfer my whole information storage into the app – Then I might must duplicate the identical storage for Android too – and it is all working wonderful within the browser – I do not need 3 variations if i can keep away from it.
For the web-app, native storage and indexeddb storage work nice.
For WKWebView, it is nice and if I want data I can request it from the web page.
However WKWebView appears to should be hooked up to a dwell view hierarchy, and can’t be hooked up to the widget view hierarchy.

Has anybody received a option to both instantiate a working WKWebView with out attaching to the view stack, or to entry the WKWebView native storage and/or indexeddb storage for a web site with out the complete WKWebView (for instance, accessing the JSContext however having it bind to a full web site)
Notice: I’m attempting to construct code that may function whereas offline, so I am unable to simply question my principal web site for information.

For instance (not truly what I am constructing but it surely conveys the concept…)
Think about an internet calendar service. The app reveals the calendar, permits new gadgets and many others. All appointments are cached domestically in indexeddb so you may open the app and see them even in case you are offline. Now you need a widget to point out the calendar. It wants entry to the identical information. Likewise, you obtain a notification of a brand new calendar merchandise simply earlier than you lose sign – you open your app anticipating to see it (in spite of everything, your cellphone’s obtained it), but it surely’s not there as a result of the notification handler cannot entry the web-context of the indexeddb

What I would like is to do…

let internet = WKWebView(noViewContext)
internet.load("https://instance.com/functionpage") // observe, counting on caching right here.  I've that sorted)
internet.evaluateJavaScript("SomeCodeHere()") { (end result, error) in and many others. and many others.}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles