How to open my UIImagePickerController on file input field in UIWebView? - ios

I want to open my UIImagePickerController when user taps on file input field in UIWebView. Currently UIWebView opens its own UIIMagePickerController on which I don't have any control.

One way to do it would be to change the url when the user taps on the file input field. There's an answer about doing something similar here: Is it possible to update a url link based on user text input?
Then your UIWebView will need to catch that url change and open your UIImagePickerController. That can easily be done with this chunk of code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString isEqualToString:#"http://www.mywebsite.com/selectpic.htm"])
{
// Your UIImagePickerController code here
}
return YES;
}

Related

YTPlayerView once loaded opens the video in youtube app

So the title pretty much sums up the situation I am loading my YTPlayerView like this:
[self.videoView loadWithVideoId:#"youtube id"];
And like it was mentioned in the documentation it works perfectly however the second time I tap on the view the video opens on the youtube app sometimes and not on fullscreen.
Any help here ?
After a lot of research I didn't find an answer to this question so I decided to dig on the YTPlayerView.m file and see how the touch event is handled and I found that there is two ways to do this:
1- the YTPlayerView contains a webView and an override of:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
This is the full code which checks the url scheme to trigger the appropriate action
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.host isEqual: self.originURL.host]) {
return YES;
} else if ([request.URL.scheme isEqual:#"ytplayer"]) {
[self notifyDelegateOfYouTubeCallbackUrl:request.URL];
return NO;
} else if ([request.URL.scheme isEqual: #"http"] || [request.URL.scheme isEqual:#"https"]) {
return [self handleHttpNavigationToUrl:request.URL];
}
return YES;
}
which was in my case this function handleHttpNavigationToUrl that returns a bool which indicates if the video should open on the app or the youtube application.
I have commented these lines that opens the video on the app and everything is ok now.
[[UIApplication sharedApplication] openURL:url];
return NO;
This is a quick fix and not good one i know but in my case i had no choice the 2nd solution is much better though.
2- The problem is in the youtube url in the first place as if you are using the embed url this problem will not occur,
so instead try to use other methods for loading the video by using the embed url, which is of the format:
http(s)://www.youtube.com/embed/[VIDEO ID]?[PARAMETERS]
so just try to use loadVideoByURL and use the embed url instead of loadWithVideoId.
Voila i hope this helps.

how to get UIPopoverController from UIWebView

I load a webpage in a uiwebviewcontroller,after click one link, it will pop a popovercontroller, is it possible to get this controller in my code?
Actually, this popovercontroller is not created by my code. The html detect the webpage is loaded by iDevice and pop this. That means, if I use safari to open webpage, it also will display this popovercontroller.
Thanks.
implement the UIWebView delegate method.
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
if([urlString isEqualToString :#"abc.com") // link on which want to open popoverview
{
UIPopoverController itemPopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
[itemPopover presentPopoverFromRect:customCell.addImage.bounds inView:webViewpermittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
return NO; //if wanted to load the link on UIWebview return YES else return NO
}
return YES;
}

Switch to next view with UIWebView

When you use the Facebook App and go to the Terms and Conditions view, there is a WebView. When you choose an option in the WebView you'll go to a new view.
Now I wanna make a login system with PHP. When the user login is succeded he'll go to an webpage. How can I set for example: When the UIWebView is on www.myserver.com/ok that the new view in my app will show?
Set your UIWebView with delegate and check :-
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"Loading: %#", [request URL]); //if url matches www.myserver.com/ok open your view
return YES;
}
Hope it helps you..

How to return last page of webview to another view from a view

I have a ios program for iPad. It is used 2 view, A view has webview, another has imageview. When I returned webview from imageview, webview is opened homepage. I want to return last page . How can I do?
If I understand you correctly, you want to make sure, that the last page that was loaded in the UIWebView will be displayed again when you switch back to the UIWebView.
To achieve that you can keep track of the last URL that was loaded in the UIWebView. You can do that in the following UIWebViewDelegate method (declare currentURL as property):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.currentURL = request.URL;
return YES;
}
And then when you bring back your UIWebView:
- (void)showWebView {
[yourWebView loadRequest:[NSURLRequest requestWithURL:currentURL]];
}

Creating Terms and Conditions link

"By clicking Register you are agreeing to our Terms and Conditions"
What is the easiest option to implement in the code where the entire above line is made clickable (this launches a modal view that shows the terms and conditions) AND the word "terms and conditions" is underlined in blue.
We tried various options.
1) We created a UIWebView and tried loading a html into it. But the html was rendered as is.
eg: "html body.../body html"
2) We tried to create a button with a label over it but we were not able to create a borderless button.
Thanks!
We were able to create the formatting by using a webView. We used one of the delegate of webView to complete the process. Here is sample code
NSString *html = #"<html><head><title>Terms and Conditions</title></head><body style=\"font-family:verdana;font-size:10px;\"><p>By clicking \"Register\" you are agreeing to our <b><u><font color=\"blue\">Terms and Conditions.</font></u></b></p></body></html>";
[termsWOutlet loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.google.com/message"]];
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(#"%s",__FUNCTION__);
NSURL* u = [request URL];
if( [[u scheme] isEqualToString:#"showlicenses"] ) {
NSLog(#"in %s",__FUNCTION__);
[self performSegueWithIdentifier:#"loadTNC" sender:self];
return NO; // DO NOT attempt to load URL
}
return YES; // if you want to allow the URL to load
}

Resources