gpt4 book ai didi

ios - NSURL :URLByAppendingPathComponent: converts ? 到 %3F,但随后 UIWebView 撤消了导致加载失败的转换

转载 作者:可可西里 更新时间:2023-11-01 05:57:05 26 4
gpt4 key购买 nike

我正在加载本地 html 页面并在 shouldStartLoadWithRequest: 中使用以下 url:

... /Library/Application%20Support/CDS/%3Fpid=27ce1ef8-c75e-403b-aea1-db1ae31e05cc/...

在该页面内,如果用户单击链接转到外部网站,则他们单击后退按钮,我的代码处理它:

if ([self.webView canGoBack])
[self.webView goBack];

然而,当 shouldStartLoadWithRequest: 因调用 [self.webView goBack] 而被再次调用时,传递给 shouldStartLoadWithRequest: 的 URL 已更改为:

`... /Library/Application%20Support/CDS/?pid=27ce1ef8-c75e-403b-aea1-db1ae31e05cc/..`.

即操作系统已将 URL 中的“%3F”更改为“?”。

我从 shouldStartLoadWithRequest 返回 YES:但是由于“%3f”变成了“?”结果是 didFailLoadWithError: 被 WebKitErrorDomain 102 调用并且页面加载失败。

文件实际上有?在其名称中,但在构建传递给 UIWebView:loadRequest: 的 NSURL 对象的过程中,iOS 系统调用将其转换为 %3F,如下所示

NSURL *fullURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory                                                                                 inDomain:NSUserDomainMask
appropriateForURL:nil
create: YES
error:&err];

fullURL = [fullURL URLByAppendingPathComponent:folderLocation isDirectory:YES];
fullRUL = [fullURL URLByAppendingPathComponent: pageToLoad isDirectory:NO];
NSURLRequest *requestObj = [NSURLRequest requestWithURL: fullURL];
[self.webView loadRequest:requestObj];

folderLocation 是一个包含 ? 的 NSString,对 URLByAppendingPathComponent 的调用会自动将其转换为 %3F,如果不进行该转换,页面加载将失败。

有人见过这个吗?

最佳答案

我没有使用文件 url,但我遇到了同样的问题。看起来这是处理它的最佳方法。

NSString *newURLString = [[origurl absoluteString] stringByAppendingPathComponent:appendedString];
NSURL *url = [NSURL URLWithString:newURLString];

关于ios - NSURL :URLByAppendingPathComponent: converts ? 到 %3F,但随后 UIWebView 撤消了导致加载失败的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12219666/

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