iOS UIWebView popup blocker issue - ios

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.

Related

ios web view accessing the camera

Any body have idea, how to access the camera through a web view app in iOS?
Currently using Xcode 9 swift. but am willing to change the complete coding, if needed.
At the moment the WKWebview is being used.
Refer to this link to see my coding. "iOS web view application accessing the camera objc" thank you.
you can open camera on changing url.
when your URL will change below method will call, you can write code for open camera inside function
// this is delegate method called while changing url.
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//Code for camera after checking url
}

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

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.

Facebook and G+ login with UIWebView

My iOS app has a login page that is set up in a UIWebView. It also has a Facebook and G+ login. I can get the normal login screen to work, alright. But I am having problems when I do that with Facebook and G+. I am assuming that the reason is the New Window that pops up with the button click.
Is there any way that I can handle this without resorting to Manual Login?
It would be much easier to use native Facebook and G+ login. What you are trying to accomplish is much more complex than using native logins.
If you really, for some reason, must do it in a UIWebView, you would have to implement some strategy like this:
override -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method of UIWebViewDelegate protocol.
in your implementation, you should open the login interface in another modal UIWebView and handle login events there, and on the dismissal of that modal view, if login was successful continue with the app flow.
That would look something like this:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
//for facebook login
if ([[url absoluteString] containsString:#"m.facebook.com"] && [[url absoluteString] containsString:#"login"]) {
// instantiate and present new modal UIViewController containing UIWebView that loads the url.
return NO;
}
//for G+ something similar
return [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
Then, the modal viewControllers for login would also have to implement the logic of how to handle the possible login events, and dismiss itself on success, which would be very complex.
The first webView would than also have to know when the modal is dismissed (can be done with protocol or some other way), and then check the login status, and proceed if successful.
So, as I said, it would be best if you used the native logins.

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.

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