使用shouldStartLoadWithRequest加载不同的URL

时间:2016-06-02 12:12:19

标签: ios uiwebview nsurlconnection nsurlrequest uiwebviewdelegate

我目前正在uiwebview中为我的ios应用使用http://something.com此链接。在这个虚拟网站上还有另一个链接。点击此链接后,我想打开本机ios相机屏幕。现在我只能为这个网址http://something.com打开cam。但我需要通过点击此http://something.com中的其他链接来打开相机。当我点击其他链接时,网址将更改为“http://something.com \ webapp”。那我怎么能让它运作起来呢?有什么想法吗?

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;

NSRange range = [urlString rangeOfString:@"http://something.com"];
if (range.location != NSNotFound) {
   [self showCamera]; //camera starts
    return YES;
} else {
    return NO;
    }

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

if ([request.URL.absoluteString containsString:@"webapp"]) {
   [self showCamera];
   return NO;
} else {
   return YES;
}
相关问题