I want to be able to save the state of a WKWebView when a user quits out of my app and be able to restore it to exactly how it was when the user returns to the app. I want it to restore websites with forms, online calculators that store the history of calculations, or any websites that make Javascript objects dynamically. How can I do this?
I have tried the createWebArchiveData method here but when saving and restore a web archive version it doesn’t put the display data back exactly how it was. When I restore it from a web archive it is like I just refreshed the page which is not what I want.
I am not able to use any of the HTML5 storage methods or use any evaluateJavaScript methods to handle this since I want to be able to save and restore the state for any website I visit.
Related
Background:
We are building a React Native app which allows users to create posts that include a quote from a blog post or news article. To achieve this, we have built a share extension, which displays a React Native view inside a modal. Inside the RN view we are using react-native-webview (which renders as a WKWebView on iOS), to display the page that was shared, allowing the user to select some text on the page (which is fed back to our app via an injected content script), and continue to create a post.
The problem:
Some news sites that our users want to share from have paywalls, e.g. FT, NY Times etc. - on these sites the user has to log in inside the webview. It's not ideal, but once they have logged in, as we have cookies enabled on the webview, their session will be remembered. This solution works well on Android, and works well on iOS when sharing from Safari.
When sharing from an app on iOS however, once the user submits the login form inside the webview, the share extension closes, taking the user back to the app that initiated the share action.
Here is a video demonstration of the issue occurring in the Guardian app:
https://www.youtube.com/watch?v=DFnh1x3j4xs
Observations:
When observing requests that occur within the webview using the onShouldStartLoadWithRequest prop of the WebView component, upon submitting the login form, there are two requests where iOS reports the navigationType as formSubmitted.
By checking the navigationType inside of the onShouldStartLoadWithRequest method, I was able to allow the first formSubmitted request to go through, but cancel the subsequent one. This prevented the share extension from closing, but upon clicking a link to go back to the home page, the share extension was closed.
My current theory is that the app which initiates the share, is somehow hooking into the form submit event, as these apps generally use webviews for their own login process - so although this webview is running in our own process, perhaps the app still somehow hooks into the process.
It is worth noting that this behaviour is inconsistent between news apps, presumably due to differences in the way they handle their login process.
Initially this issue was occurring in the BBC app as well, but at some point stopped occurring without us making any changes, so it is somewhat intermittent, or perhaps based on stored data/cookies.
Summary
We would like to fully understand why this behaviour occurs, and we're hoping there is a solution or workaround that will prevent the share extension from closing when the login form is submitted.
I have requirement to update application containing viewcontroller from todayextension widget view controller when app is in either in background/foreground state. Lets assume.
App containing viewcontroller contains list of information. Next press on home button app goes to background state.
Now open widget and show list of information as shown in app containing viewcontroller in TodayExtensionViewcontroller.
If you update any information in TodayExtensionViewController same information I want to replicate in App containing viewcontroller when app goes from background to foreground state.
Your app and Today extension have to be able to share data.
First of all, you have to add the "App Group" capability to the App IDs of both your app and your Today extension so that they can access shared data.
The easiest way to share data is to use shared user defaults, but it is also possible to share a persistent Core Data store, for example.
Every time your app enters the foreground, it should check if the shared data has changed (or just reload its data from the shared store) so that changes made in the widget take effect.
Every time the user changes data in your app (or at least before the app becomes "inactive"), the app should update the shared data so that the widget is up to date.
This guide by Apple is a good starting point. Moreover, there are lots of good tutorials available that explain "data sharing" in much more detail.
Does anyone have idea, how to download HTML page from UIWebview along with the resources - for offline storage, so user will be able to access web page, even when there is no internet.
It should be achieved without ASIWebPageRequest, since ASIWebPageRequestdownloads a webpage directly from URL. I need to save webpage directly from UIWebview, so that values of radio buttons, textfields etc input by user can be preserved, and load it in the same state later.
Actually, I am displaying surveys webpage offline. If user downloads a webpage after filling some information, it has to be saved in that state. When user opens app later, he should find webpage in the state he left off last time.
Any suggestions are welcome. Please note that this Question is not about caching webpage. It has to be saved in directory. Thanks.
My iOS/Parse app allows multiple users to modify data which is shared among everyone. So if user 1 modifies the data I want the rest of the users to be notified of the change so that they can request the new data. I'd like this to happen in the background. So, if I have the app open and other user makes a change I want to get those changes as soon as possible (kind of like a shared notes app).
Does Parse support this type of data modification notification? If it doesn't I'd have to do something ugly like periodically poll for changes. :-(
I'm writing the cache for an iOS app right now. I'm wondering how often i should refresh my cache. to give a little background, it's a weight loss app. what i'm working on right now, specifically, is a list of recipes. I pull the list of recipes from the server and display it in a table view. Obviously, i was going to make the list refresh when you pull down on the view controller. My question is, should i have it refresh the list every x number of days? or should it refresh every time the app is reopened? the list isnt expected to change more than once every 1 - 2 weeks, if that often. the user can also add their own recipes, so it could potentially change more often than that. is there a specific industry standard or protocol to follow for how often the cache should be refreshed?
Why don't you hook up your app with a Push Notification Service ? so incase there is a new recipe you could dispatch a push notification and when the user opens the app refresh your cache. That way you only refresh your cache when needed and also aids in better user experience. Here's a good tutorial on setting up a push notification service