iOS UIWebView intercept link click - objective-c

Is it possible intercept when a user clicks a link in a UIWebView and retrieve the link?
I wish to block the UIWebView from going to the clicked link and do something else.
Thanks in advance.

Yes, look at the UIWebViewDelegate Protocol Reference, specifically webView:shouldStartLoadWithRequest:navigationType:
The NSURLRequest will let you know where the link they clicked is going to direct them.
You would simply return NO on this method if you want to prevent the request from loading.

Related

Customizing the post to facebook in Sharekit2.0

I have integrated the latest sharekit code into my project. I am able to click in, to go to the facebook and able to see the text I am going to post.
I would like to change two things.
Firstly, I am not able to see the cancel or post button because of my app picture at top. So I would like to set the view to be scrollable. How do I change that?
Secondly, I would like to remove the keyboard after I press return, or I want a way to remove the keyboard.
Thirdly, when i click the text edit, it gives me Error: HTTP status code: 404. How to solve this?
Need some help on this..Thanks..
if you use following code it will dissmiss the keyboard.
[self.view Endediting:YES];
ShareKit never seemed to be customizable. Personally, I had displeasure to integrate it into the project to post images to Flickr and Twitter, but nothing else. For what I see there now, ShareKit is still using old FacebookSDK (or at least it look so).
For better customization, I'd suggest to throw away Facebook from your ShareKit and just use new FacebookSDK.
[yourtextview resignFirstResponder];
this will remove the keyboard
Or as a general case, you can use this: [self.view Endediting:YES];

Open links Explicitly in Safari from a Table Detail View

All,
I have rich text, with links, in my UITableView's detail View:
When a link is pressed, the URL is loaded into the UIWebView where the rich text is being displayed. I'd like the URLs to open in Safari instead.
Can someone tell me how to accomplish this correctly? Is there a UIWebView delegate method suited for this purpose?
Thanks
// where url is an NSURL
[[UIApplication sharedApplication] openURL:url];
This will open the link in the default OS browser.
Documentation here.

Detect taps of links/numbers in UITextView

theres no way to detect weather the user taped on a phone number and/or link in a UITextView is there?
There doesn't seem to be a delegate method for it.
Any ideas?
You cant with UITextFied, but if you use a webview and get it to load a string with html tags for links, you can use the should load method to detect whats doing.

Getting current selection in objective c using WebKit framework?

Is there any method available in WebKit framework which tells that user has clicked on a particular button of the the web page or user clicked on some link.I want to perform some action when user clicks on a button of a webpage,but i am not able to identify that that user clicked on a button.I searched a lot but i am not able to find such method.Please help!
Set the UI delegate and the policy delegate via [webView setUIDelegate:] and [webView setPolicyDelegate:], and implement the delegate methods explained in Web UI delegate protocol reference and in Web Policy delegate protocol reference.
Look for webView:mouseDidMoveOverElement:modifierFlags: in the UI delegate and webView:decidePolicyForNavigationAction:request:frame:decisionListener: in the policy delegate to achieve what you want to do.

Restricting user interaction in UIWebView

I want to restrict the users from using the links in a UIWebView. Hence, showing only single a HTML page with no navigation.
I know I can do that using the "User Interaction" option of UIWebView but I can't use that since it disables scrolling as well, and the user cannot view the complete page.
Any ideas?
My situation demanded that a user really can ONLY look at the page, but not interact at all (specifically with respect to copying content--it was a security issue). Here's what I did:
for (UIView *thisView in webView.scrollView.subviews)
{
thisView.userInteractionEnabled = NO;
}
If you don't mind them seeing the links, you could use a UIWebViewDelegate to detect when a page begins loading and cancel it.
If you don't want them to see the links at all, you could modify the HTML before rendering it. Using libxml is pretty easy's and it's htmlparser.h can probably do what you need. If you don't like that, HTML tidy works well too.
You can wrap the WKWebView in a UIView and then set webViewWrapper.isUserInteractionEnabled = false
to disable navigation with links
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
webView.stopLoading()
}