- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在加载本地 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/
我的具体问题是关于使用 URLByAppendingPathComponent 但该原则适用于许多其他类/方法和情况。 我有以下(缩写)代码: NSData *packageData = [[NSDa
我的程序中有以下内容: return [directory URLByAppendingPathComponent:fileName]; 用调试器检查,fileName 是 __NSCFString
我正在开发一个 cordova 应用程序并尝试将它生成的 swift 代码转换为 swift 3 语法,因为当我尝试构建它时它会产生错误。我有这个功能 init(configuration: WebA
我已阅读文档,看起来某些边缘情况可能有所不同(尾部斜杠等),但我不清楚这两种方法之间的主要区别是什么。 Component 和 Extension 这两个术语在 URL 世界中是否有除我以外的人理解的
在我的项目中,我将 jsondata 保存到名为 AllBooking.json 的本地 json 文件中。 代码: NSURL *fileURL =[[self applicationDocumen
我目前正在 Xcode 7 和 ios 9 上使用 SpriteKit,我遇到了建议的 URLByAppendingPathComponent 方法,该方法用于访问文件的本地 url 并结合 arch
我的错误是:“String”类型的值没有成员“URLByAppendingPathComponent” 我在这一行中遇到了错误: let savePath = documentDirectory.U
我正在关注 a basic tutorial关于在 Swift 中构建一个简单的 iOS 应用程序。 它是用 Swift 2.x 编写的,我使用 XCode 8 Beta 和 Swift 3。 本教程
我正在加载本地 html 页面并在 shouldStartLoadWithRequest: 中使用以下 url: ... /Library/Application%20Support/CDS/%3Fp
我是一名优秀的程序员,十分优秀!