我想将更改的文件加载到UIWebView中,我希望它们在file:// scheme下加载,这样我就可以在我的页面中包含其他file:// resources(例如html5视频元素).为此,我实现了自己的NSURLProtocol并覆盖了file:// URL子集的加载.
我的startLoading方法看起来像:
- (void) startLoading {
... data is populated ...
[protocolClient URLProtocol:self didLoadData:data];
[protocolClient URLProtocolDidFinishLoading:self];
}
Run Code Online (Sandbox Code Playgroud)
这适用于iOS4/5但在iOS 6 beta 4上我收到以下错误:
2012-08-21 16:06:07.236 TemplateApp[57283:1d403] 57283: CFNetwork internal error (0xc01a:/SourceCache/CFNetwork_Sim/CFNetwork-606/Connection/URLConnectionClient.cpp:2341)
/SourceCache/WebCore_Sim/WebCore-1634/wak/WKView.mm:385 void WKViewAddSubview(WKViewRef, WKViewRef): invalid parameter
2012-08-21 16:06:07.272 TemplateApp[57283:1e603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSSetM addObject:]: object cannot be nil'
*** First throw call stack:
(0x29d0552 0x2733e7e 0x2a5dc08 0x69c6c1e 0x69c4c88 0x69c543b 0x5b40dbd 0x5b40f0f 0x5b3c240 0x5ff8060 0x5ff75d1 0x5eb8d08 0x65a4fb2 0x678486f 0x677fa3d 0x7b3ab1 0x7b2d63 0x7f0e5a 0x2972ebd 0x7f14dc 0x7f1455 0x6db410 0x29544ff 0x2953f2f 0x2976cf4 0x2976504 0x29763db 0x69d0530 0x907caed9 0x907ce6de)
libc++abi.dylib: terminate called throwing an exception
Run Code Online (Sandbox Code Playgroud)
我通过添加didReceiveResponse对我的startLoading方法的调用解决了这个问题,如下所示:
- (void) startLoading {
... data is populated ...
[protocolClient URLProtocol:self didReceiveResponse:[[NSURLResponse alloc] init] cacheStoragePolicy:NSURLCacheStorageAllowed]
[protocolClient URLProtocol:self didLoadData:data];
[protocolClient URLProtocolDidFinishLoading:self];
}
Run Code Online (Sandbox Code Playgroud)
但是现在在iOS 5和6上,我在尝试加载页面时收到以下错误:
Webview error: Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x9d4c0a0 {NSErrorFailingURLKey=file:///src/index.html, NSErrorFailingURLStringKey=file:///src/index.html, NSLocalizedDescription=Frame load interrupted}
Run Code Online (Sandbox Code Playgroud)
我在didReceiveResponse方法中尝试了各种不同的NSURLResponse对象,但没有一个允许WebView加载页面.使用除file://之外的URL方案也可以,但是我不能将file://路径用于嵌入式资源,例如HTML5视频.
有没有办法为特定文件加载动态内容:// URL到iOS 6 beta 4的UIWebView?
我目前在将内容加载到 UIWebView 时遇到一些其他问题,但我认为您需要使用NSURLResponse'sinitWithURL:MIMEType:expectedContentLength:textEncodingName:
否则我认为你没有有效的响应对象。我遇到的问题是,在我startLoading接到电话之前,我就收到了“错误的网址”。
更新:我现在开始工作了,显然我的canonicalRequestForRequest:很愚蠢
| 归档时间: |
|
| 查看次数: |
6848 次 |
| 最近记录: |