我尝试使用下面的代码在 Safari 中打开我的 HTML5 应用程序中的链接。但是,该代码还在 Safari 中打开了用于应用程序内部导航的 # 链接。链接是否以 HTTP 开头,导致它们在 Safari 中打开?如果是这样,我该如何修改此脚本以排除它们?
谢谢。
以供参考
请在此处查看 GIT 存储库:https ://github.com/philhudson91/flaming-cyril
或者我可以写它来阻止来自我托管的域的链接打开吗?
更新
这是我现在使用的代码...
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *requestURL =[ [ request URL ] retain ];
NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"#"] invertedSet];
if ([ [ requestURL scheme ] isEqualToString: @"http" ]) NSLog(@"HTTP"); if ([ [ requestURL scheme ] isEqualToString: @"https" ]) NSLog(@"HTTPS"); if (( [ [requestURL absoluteString] rangeOfCharacterFromSet:set].location == NSNotFound )) NSLog(@"Not Local"); if (( [ [ requestURL scheme ] isEqualToString: @"mailto" ])
&& ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];
}
[ requestURL release ];
return YES;
}