Restricting user interaction in UIWebView - cocoa-touch

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()
}

Related

Using a Webview in a modal NSSheet

I am having an issue similiar to this SO question. I would like to have a webview in an NSSheet in which I am doing some authentication to retrieve an API token.
I created a new NSWindowController subclass with a corresponding xib file. This is how I am starting the NSSheet:
- (IBAction)startAuthentication:(NSButton *)sender {
self.authController = [[AuthenticationWindowController alloc] initWithWindowNibName:#"AuthenticationWindow"];
[[NSApplication sharedApplication] beginSheet:self.authController.window
modalForWindow:[self.exportManager window]
modalDelegate:self
didEndSelector:#selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
In the windowDidLoad callback of this authenticationWindowController I am directing the webview to the URL:
- (void)windowDidLoad
{
[super windowDidLoad];
[[self.webView mainFrame]loadRequest:[NSURLRequest requestWithURL:authURL]];
}
It looks great at first sight: if I press the button, the startAuthentication action method is called and the new window is animated into the parent window and the authURL is loaded. The website is displayed correctly with its HTML form containing two input fields (username and password).
The problem is, that I can click on the page and it works, however if I am trying to click into one textfield, so that this field gets focus it does not work. No cursor appears in the text field of the website's form and after each keystroke I hear the NSBeep() sound.
I did some research on this topic and I found two references:
How do I use a WebView in a modal dialog?
Cocoa topics: the case of the modal WebView
What kind of puzzles me is that there is the Facebook Exporter for Aperture Plugin, which shows exactly what I want: a webview in a modal sheet. However I cannot find out what they are making differently . In the Facebook Exporter I have not found any code interacting with the run loops directly.
My questions
Is this a known problem with webviews in modal sheets?
Are the problems explained in the two references still there?
How can I get this working? I do not understand when to switch the runloop mode for example.
there is no general problem with this and I just tried it out again. must be some code besides this? can you narrow it down to the sheet? btw: my sample:
https://dl.dropbox.com/u/3753090/test2.zip
BUT all that said, modal runmode and webviews / timers / networking isnt very waterproof :)
because: when you go modal via one of the convenience methods in NSApp, the runloop is only run in a very limited way. :/

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];

iOS UIWebView intercept link click

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.

XCode 4. Keyboard doesn't hide on iPad

I have a problem with my iPad app.
I perform authorization in social networks (facebook, twitter etc.) to post information from app. Several webviews change each other (login, content of post, captcha). They have text fields and I have to show keyboard. After posting I return to some start view with posted information.
It works good, but after posting first news something goes wrong. When I post news one more time, after return keyboard is still on the screen.
I saw here some questions familiar to this, but they wasn't useful.
I tried to make resignFirstRersponder to all webViews, textFields and textViews. Also i\I tried to implement method disablesAutomaticKeyboardDismissal but it doesn't help me.
I don't know where search for problem...
So questions are: why could this happened? How can I solve this? fnd How can I get some information about keyboard? (is it visible, what object has focus etc., anything that could be useful to solve problem)
And one more thing. I have similar app for iPhone and it seems to work correct.
Try this:
[searchBar performSelector:#selector(resignFirstResponder) withObject:nil afterDelay:0.1];
Make sure to replace searchBar with the object that is the actual First responder in your case
Problem is fixed, finally. The reason was the way I had changed visible view. I set a new value to view property of ViewController. And as previous view contains text field with focus on it, focus wasn't lost before changing view (and keyboard was still on the screen), but I had lost handler to previous view.
Solution is: resignFirstResponder to all (or current) inputs BEFORE changing view.
Hope, it's clear. Thanks for your help!

Can I hide the Action button on the UIDocumentInteractionController view?

I wanted to know if I can hide the Action button on the UIDocumentInteractionController so a user couldn't actually open the document in another app?
I found something that works for me well enough:
- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller canPerformAction:(SEL)action{
return false;
}
It still shows the button but the popover that appears only has the print form but the print button is disabled.
The whole purpose of the UIDocumentInteractionController is to show the user which applications can handle a file and give them a way to 'send' the file to the app they choose. Since hiding/disabling the button would confuse the user, I doubt it is possible (at least not without resorting to undocumented method calls).