开发者

How can I check if a WebView URL is a local file?

开发者 https://www.devze.com 2022-12-12 13:53 出处:网络
I have this question that is unsolved for me.... I need to check if the current URL of my webview is a local file in the Documents directory of my app....how can I do this??

I have this question that is unsolved for me.... I need to check if the current URL of my webview is a local file in the Documents directory of my app....how can I do this??

Thanks!开发者_JAVA百科


You can check:

[request.URL isFileURL];

More information here.


Check the URL's scheme. Assuming you have an NSURL* instance called myURL:

if ([[myURL scheme] isEqualToString:@"file"]) {
    NSLog(@"URL %@ is local", myURL);
}

Read Apple's NSURL specification to learn more about accessing different parts of an URL.

Assuming you have a UIWebView* called myWebView, you might call something like:

[[myWebView request] URL]

to get the NSURL* of what the web view currently has loaded. Then you can call that object's scheme as described above.


Check for the file:// protocol in the URL.

0

精彩评论

暂无评论...
验证码 换一张
取 消