How can I check if a WebView URL is a local file?
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.
加载中,请稍侯......
精彩评论