我在我的应用程序中添加了自定义 URL Scehme。喜欢 myapp://
所以每当它检测到 myapp://http://google.com .它应该重定向到我的应用程序。以及如何在 webview 上显示 URL。
在 Appdelegate:
- (BOOL)applicationUIApplication *)application handleOpenURLNSURL *)url {
NSString *strURL = [url.absoluteString stringByReplacingOccurrencesOfString"myapp://" withString""];
WebViewController *objWebView = [[WebViewController alloc] initWithNibName"WebViewController" bundle:nil] ;
objWebView.url=strURL;
[[[UIApplication sharedApplication]keyWindow].rootViewController presentViewControllerbjWebView animated:YES completion:NULL];
return YES;
}
但是当我使用该 URL 加载请求时。它在该 URL 之前附加 file://我如何在 Web View 中加载 URL。
NSURL *targetURL = [NSURL URLWithString:self.url];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
NSLog(@"%@",request.URL); // O/P : htpp//google.com
开启 shouldStartLoadWithRequest
-(BOOL)webViewUIWebView *)webView shouldStartLoadWithRequestNSURLRequest *)request navigationTypeUIWebViewNavigationType)navigationType{
{
NSLog(@"%@",request.URL); file://htpp//google.com
return true;
}
最后它失败并出现错误
Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not
found on this server." UserInfo=0x7983bb30
{NSErrorFailingURLStringKey=file://htpp//google.com,
NSErrorFailingURLKey=file://htpp//google.com,
NSLocalizedDescription=The requested URL was not found on this
server., NSUnderlyingError=0x78fbbe70 "The requested URL was not found
on this server."}
Best Answer-推荐答案 strong>
您的网址错误。 htpp//google.com 是什么?应该是 http://google.com
关于ios - WebView自动添加文件://before URL,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/27844286/
|