Detect empty page in WKWebView - ios

I have an iOS application which uses a WKWebView to display a webpage I do not have under my control. This webpage is a PWA (progressive web app) which at some points uses history.back(). Throughout the application this is no problem, but when called on the "start" page, nothing happens.
Flow:
Empty (= freshly initialised webview)
webView.load(URLRequest(url: URL(string: "https://pwa.example.com")!))
User presses button in pwa which calls history.back()
Nothing happens
In regular, desktop browsers this leads back to the start/new-tab page (if launched in empty tab/window) or to the page that was loaded before.
My goal is to detect that we are at the "start" again and close the webview. I tried every method from WKNavigationDelegate & WKUIDelegate but with no success so far.

Related

Instantly open Web Inspector for iOS WebView

I'm developing an iOS app with WebView.
I need to debug is so that's what I do:
Open WebView on iOS
Go to desktop Safari -> Develop -> iPhone ->
The problem is some script takes place the moment WebView opens. So when I open Web Inspector all I see is just a blank page.
Is there any way to pause page processing before Web Inspector is opened?
For such cases, I would place a UIButton somewhere in the layout, and request the url, only when the button is pressed. That is you will have a WKWebView initiated and available in your screen and you only navigate to the url path on the tap event of the UIButton.
This is just for debugging purposes.

In iOS, is it possible open a url in safari, then go back to the app and reopen safari without pushing a new url?

I have a simple app that opens a link in Safari with UIApplication.shared.open. The user might navigate to any number of urls in the site, and then hit the Back arrow in the top left corner as return to the app. Is it possible to launch Safari again, but without a new url, and simply open the tab at the same url location where navigation stopped, prior to pressing the back button? The only way I know to open Safari is to push a url it, which means a user cannot resume using a site in Safari where they left off. I would appreciate any ideas on how to implement this feature.

Stop webview reload/refresh when app comes to Foreground

I m working on a multiview UIWebView. This webview loaded an external url. This url get reloaded everytime the app comes to the foreground and goes to the first page. This is causing the user to enter any kind of data again and again. Is there a way to stop this url from reloading from webview?
I have already tried using:
1. [self.webView stopLoading];
2. shouldStartLoadingWithRequest making it return NO;
3. UIWebViewNaviagationTypeReload and UIWebViewNaviagationTypeOther
to check if the webviews load status.
But no luck. The Webview keeps reloading?
Can anyone tell me is there any other way to stop the refresh for this url inside webview?

Performing a task through a website and going back to an iOS app

I'm developing an iOS 7+ app that I need to offer the option of navigating to a certain web page to let the users to fill in a form there, and after that to come back to the app's view where the user was.
Is it possible to programmatically open Safari with a given url? If it is, I suppose that then there is no way to automatically redirect the user to your app from there... right? Is then a UIWebView the only option? Is it possible to navigate back or dismiss the view with the UIWebView without the need of user interaction?
Thanks
You can open links in Safari as detailed in this post How to launch safari and open URL from iOS app
I don't believe you can set a 'callback' and have it return to your app on completion, as you have no control over the user once they have exited your app's sandbox.
Opening the link in UIWebView would provide control, as you can utilize the UIWebView callbacks.

Is it possible to navigate back to the starting point when external links are clicked in a UIWebView?

I've put together a very simple proof of concept app using a UIWebView (and a regular controller) to display a web page.
If the web page has external links then when clicked on the app will switch to the web app.
However there's no way to get back to my original app.
If I add a navigation controller will I get the ability to navigate back, or is there something else additionally that would be required?
(As well as launching web pages it will also be necessary to intercept custom links in the web page and perform some associated action, such as add a contact, in this situation I would also like to be able to navigate back to my app).
TIA
If your links open in Safari, the only way for your user to get back to your app is via the multitasking bar (or obviously quitting and tapping on your app icon)- there is no way to bring your app to the forefront programmatically from within another app.
I am confused though, if you have a UIWebView, the default behavior of clicking on links is to load the linked page in the same web view.
In any case, I think what you are wondering is how to intercept link clicks of a UIWebView so to do that, you should implement the delegate method:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
You can then test for clicked links via testing the navigationType property for UIWebViewNavigationTypeLinkClicked

Resources