【问题标题】:Different URL Load with shouldStartLoadWithRequest使用 shouldStartLoadWithRequest 加载不同的 URL
【发布时间】:2016-06-02 12:12:19
【问题描述】:

我目前在我的 ios 应用程序的 uiwebview 中使用 http://something.com 这个链接。在这个虚拟网站中还有另一个链接。单击此链接后,我想打开本机 ios 相机屏幕。现在我只能为http://something.com 这个网址打开凸轮。但我需要通过单击此http://something.com 中的另一个链接来打开凸轮。当我单击另一个链接时,URL 将更改为 ``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;
    }

【问题讨论】:

  • 您可以使用 "[urlString containsString:@"your other url"]" 检查其他链接是否存在。如果存在,您可以打开相机。"containsString" 可从 iOS 8.0 获得
  • 你能给我一个例子,我将如何使用 containsString 打开位于http://something.com 内的另一个链接http://something.com/webapp? @sanman
  • 我的意思是你可以使用“containsString”来检查你被重定向到的字符串。而不是在单击按钮后使用 NSRange.i.e。检查里士满的答案。

标签: ios uiwebview nsurlconnection nsurlrequest uiwebviewdelegate


【解决方案1】:

这应该可以解决问题:

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

【讨论】:

    猜你喜欢
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2019-07-18
    • 2023-03-18
    相关资源
    最近更新 更多