Catching if a web text field is tapped on iOS - 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.

Related

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.

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.

Facebook like Button with user authentication

I am developing a ipad application in that i need to include facebook page like button. I have loaded the button using iframe in webview, when user clicked on the button if they already sigh in just count should increment or decrement else pop up will ask them to login first. once they logged in then increment the count automatically.
Any sample for code to do step by step.
Here is my webview like button code
NSString *likeButtonIframe = #"<iframe src='http://www.facebook.com/plugins/likebox.php?id=XXXXXXXXXXXXXXX&width=292&connections=0&stream=false&header=false&height=62' scrolling='no' frameborder=0' style='border:none; overflow:hidden; width:282px; height:62px;' allowTransparency='true'></iframe>";
NSString *likeButtonHtml = [NSString stringWithFormat:#"<HTML><BODY>%#</BODY></HTML>", likeButtonIframe];
[_webView loadHTMLString:likeButtonHtml baseURL:[NSURL URLWithString:#""]];
Also i have tried before shows like i will ask him to login first then display the like button and ask them to like.
I used UIWebView's delegate method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
to detect when user does not have active session.
Here is my sample code: https://github.com/gneil90/facebook-likebox-ios-login
As per Facebook you should not have a like button in the app, that is to avoid spam likes.
Even through we can implement it using iFrame & UIWebView.
RayWinderlich has a great tutorial for this Facebook Like Button in iOS app.
Follow this link to generate a Facebook like frame for your page.
And use accordingly in your app, one limitation is that if user is not logged in it shows a login screen within it. So if your webView is small, it will be issue. Check out the sample from tutorial, and implement as per your requirements.

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