我们有一个“关于我们的应用程序”popover,它是html格式的,基本上是一个popover中的UIWebView。还有一个到我们网站的href链接。问题是如果你点击链接,它只是在popover中打开我们的网站。有没有办法改变该链接发生的事情,比如打开Safari以便它在一个完整的浏览器中,或者至少增加popover大小,因为我们的About the App窗口很小。
答案 0 :(得分:2)
是的,this post为在Safari中打开的每个http,https和mailto调用提供以下代码:
-(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;
}
您可以通过从请求中获取网址来仅修改某些网址。
答案 1 :(得分:2)
我使用此代码通过UIWebView打开URL:
- (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];
}
}
答案 2 :(得分:0)
您是否测试了UIWebView委托的- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
方法?
webview应该在每次加载另一个框架/页面时询问其代理,因此如果单击该链接,则会调用该方法。
然后你必须返回NO
并按照你想要的方式处理请求!