iOS web view delegate methods are not getting called on Webpage navigation - ios

Can not catch when web view change it's url without loading the page.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
This delegate method is getting called when loading the webpage for the first time.But after that if the webpage navigate on clicking of a button none of the delegate methods is getting called.If I load the page in browser I can see the URL change. Webpage is using History.pushState to change the URL.

Related

iOS UIWebView goback or goforward always reload webView automatically, How can I stop the webview reload?

iOS UIWebView goback or goforward always reload webView automatically, How can I stop the webview reload? Because some urls like "https://www.sina.cn/", If the webview request the url ,You'll notice that the webview can't goforward. And how do I deal with this situation?
You can see my code at https://github.com/misscxuan/WebBackTest
if the webview request the url as "https://www.sina.cn/", and request another url, then webview goback, you'll find webview can't goforward.
You could stop the load task in the UIWebviewDelegate Method - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType.

iOS UIWebView popup blocker issue

In iOS, the default behavior when I open my webpage is that after login it opens the next page in a new window. But now when I open it in iOS webview, it does not open the next page. I google about it, and the cause seems to be the popup blocker. So, is there any simple way to disable the popup blocker in the iOS webview?
The webpage might have a redirection that you are not handling properly.
You may first want to use webView:didFailNavigation:withError: or webView:didFailProvisionalNavigation:withError: to get some reasons or clues. And you can try to debug webView:decidePolicyForNavigationAction:decisionHandler: to see whether you are allowing the navigation.
If the redirection somehow generates an about:blank page in the transition, you could try to use UIWebViewDelegate's webView:shouldStartLoadWithRequest:navigationType: and returns a YES if request.URL.absoluteString is indeed about:blank, for example:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString isEqualToString:#"about:blank"]) {
return YES;
}
return NO;
}
BTW, you also can try to use Safari to debug webViews in your simulator. For instance, try document.location in your inspector to see what actually is the URL when the page doesn't open.

UIWebView not working first time in iOS 9

I have a UIWebView, whose delegate is set in viewDidLoad and then a URL is passed to it. This screen is loaded once the app launches. The webviewdoesn't load the URL and the delegate method (given below) is not called
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
There is a button on the same screen. When i press that after app launches. The same Web view loads.
Please tell me why my UIWebview is not loading for the first time?
It happens only in iOS 9. In iOS 8, it works perfectly.
Add below key in you .plist and try.

Intercepting a click in a UIWebView on iOS

I need to intercept a click on a UIWebView on a video pre-roll advertisement and have this displayed in a new popup window instead of in the UIWebView which is quite small on the screen.
The issue is that I don't know what the URLs that are being clicked and also that these clicks are processed via Javascript on the page as well. There would also be Javascript reporting/tracking calls going out from the UIWebView in the background.
Is there anyway to detect that the UIWebView is opening a new page and instead of displaying that in place it get's displayed in a popup?
Great question. All you will have to do is implement the UIWebViewDelegate protocols.
This method:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
is likely the one you will use to detect all events happening within the UIWebView.

Catching if a web text field is tapped on iOS

In my iOS app I have a UIWebView which works fine. What I am unable to get is which function is invoked when user taps on a text field in a displayed webpage. To make my problem clearer:
If I display google in the UIWebView and then tap on the search bar, UIWebView automatically pops up the keyboard. I want to know how does UIWebView detects the search bar being tapped. What function is invoked on this tap?
I am sure it is not
webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSMutableURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Method, for it is not navigating to any new page.

Resources