Reputation: 37581
Within UIWebView:shouldStartLoadWithRequest:
, I'd like to know if the page being loaded is a local file or a remote file. Is there an easy way of finding this out?
I suppose every time a file is loaded I could search the filesystem looking for the file, but is there another way?
Upvotes: 0
Views: 125
Reputation: 10608
Yes it is possible. You should use a regular expression to test against the hostname. Local pages won't match the regular expression.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
static NSString *regexp = @"^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9-]*[a-zA-Z0-9])[.])+([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexp];
if ([predicate evaluateWithObject:request.URL.host]) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
} else {
return YES;
}
}
Upvotes: 0
Reputation: 42588
You should be able to tell the kind of request it is by the kind of URL.
It should be as simple as file:…
vs http:…
or https:…
.
Upvotes: 1