gpt4 book ai didi

ios - WebView自动添加文件://before URL

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:30 26 4
gpt4 key购买 nike

我在我的应用程序中添加了自定义 URL 方案。像 myapp://

所以每当它检测到 myapp://http://google.com .它应该重定向到我的应用程序。以及如何在 webview 上显示 URL。

在 Appdelegate:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSString *strURL = [url.absoluteString stringByReplacingOccurrencesOfString:@"myapp://" withString:@""];

WebViewController *objWebView = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil] ;
objWebView.url=strURL;
[[[UIApplication sharedApplication]keyWindow].rootViewController presentViewController:objWebView 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

ON shouldStartLoadWithRequest

    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)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."}

最佳答案

您的网址有误。 htpp//google.com 是什么?它应该是 http://google.com

关于ios - WebView自动添加文件://before URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27844286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com