Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C-覆盖UIWebView中的URL?_Objective C_Uiwebview_Overriding - Fatal编程技术网

Objective-C-覆盖UIWebView中的URL?

Objective-C-覆盖UIWebView中的URL?,objective-c,uiwebview,overriding,Objective C,Uiwebview,Overriding,是否可以覆盖UIWebView中的URL?例如,如果我想检测tel:links,并将+1添加到数字的开头(如果它还没有) 在Android上,我是这样做的: public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("tel:1")) { Intent intent = new Intent(Inten

是否可以覆盖UIWebView中的URL?例如,如果我想检测tel:links,并将+1添加到数字的开头(如果它还没有)

在Android上,我是这样做的:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith("tel:1")) {
                        Intent intent = new Intent(Intent.ACTION_DIAL,
                                Uri.parse(url)); 
                        startActivity(intent);
                    }
                else if (url.startsWith("tel:")) {

                    int start = url.indexOf(":");
                    String suffix = url.substring(start + 1);
                    String newUrl = "tel:1" + suffix;
                        Intent intent = new Intent(Intent.ACTION_DIAL,
                                Uri.parse(newUrl)); 
                        startActivity(intent); 
                }

                else if(url.startsWith("http:") || url.startsWith("https:")) {
                    view.loadUrl(url);
                }
                return true;
            }

如何在Objective-C中实现这一点?

您可以实现
webView:shouldStartLoadWithRequest:navigationType:
webView委托方法。检查“单击”的类型,然后检查请求的URL,查看它是否是
tel:
URL。如果是这样,您可以根据需要处理URL

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        NSURL *url = request.URL;
        NSString *scheme = [url scheme];
        if ([scheme isEqualToString:@"tel"]) {
            // Update the url as needed

            // Now handled the url by asking the app to open it
            [[UIApplication sharedApplication] openURL:url];
            return NO; // don't let the webview process it.
        }
    }

    return YES;
}

美丽的。正是我需要的。谢谢