Reputation: 878
We have an "About our app" popover that is html formatted and basically a UIWebView in a popover. There's also a href link to our website. The problem is if you click on the link, it just opens up our website in the popover. Is there a way to alter what happens for that link, like open up Safari so it's in a full browser, or at least increase the popover size since our About our App window is small.
Upvotes: 1
Views: 2302
Reputation: 8109
I use this code to open URL via UIWebView:
- (BOOL)webView:(UIWebView *)webView_ shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
self.curURL = request.URL;
if ([request.URL.scheme isEqualToString:@"file"])
{
return YES;
}
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:@"Cancel"
otherButtonTitles:@"Open in Safari", nil];
[actionSheet showInView:self.view];
[actionSheet release];
return NO;
}
#pragma mark -
#pragma mark Action sheet delegate methods
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == actionSheet.firstOtherButtonIndex + eSafariButtonIndex)
{
[[UIApplication sharedApplication] openURL:self.curURL];
}
}
Upvotes: 2
Reputation: 1735
Yes, this post gives the following code for every http, https and mailto call to open in Safari:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *requestURL =[ [ request URL ] retain ];
if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ])
&& ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];
}
[ requestURL release ];
return YES;
}
You can modify for only certain URLs by getting the URL from the request.
Upvotes: 2
Reputation: 12719
Have you tested the - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
method of the UIWebView delegate?
The webview should ask its delegate each time it loads another frame / page, so if you click on the link the method is called.
You then just have to return NO
and handle the request the way you want !
Upvotes: 0