NSURLProtocol 用本地资源替换远程请求,video 在 smilulator 上可以播放,在 iPad , iPod touch 上不可以

2014-06-05 14:13:23 +08:00
 nkwhya
NSURLProtocol 实现用本地资源替换远程请求,video在smilulator上可以播放,在ipad,itouch上不可以,报如下错误: 有大拿知道怎么解么,在simulator上会收到有range请求头的request ,在device上没有这个log...

<Warning>: 20 +0.160515 sec [01d3/060b]: error: ::task_for_pid ( target_tport = 0x0807, pid = 469, &task ) => err = 0x00000005 ((os/kern) failure) err = ::task_for_pid ( target_tport = 0x0807, pid = 469, &task ) => err = 0x00000005 ((os/kern) failure) (0x00000005)
com.apple.debugserver-310.2[467] <Warning>: Could not get task port for process, sending SIGKILL and exiting.
webviewP[469] <Error>: <<<< FigPluginView >>>> -[FigPluginView validationFailedWithMessage:resultCode:]: unplayable URL (http://myapp/music.mp3) (error=0 -- Movie could not be played.)
3438 次点击
所在节点    程序员
3 条回复
CDuXZMAPgHp1q9ew
2014-06-05 15:31:54 +08:00
试试重载uiurlcache
#import "HPURLCache.h"


@implementation HPURLCache

- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request {

NSString *pathString = [[request URL] absoluteString];
NSLog(@"request %@",pathString);

if ([pathString hasSuffix:@"scriptstyle_1_post.css?i5D"]) {


NSData *css = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"scriptstyle_1_post" ofType:@"css"]];

NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[request URL]
MIMEType:@"text/css"
expectedContentLength:[css length]
textEncodingName:nil];
return [[NSCachedURLResponse alloc] initWithResponse:response data:css];

}

return [super cachedResponseForRequest:request];
}
nkwhya
2014-06-05 16:04:36 +08:00
@wujichao 这个方法也试过了,video在simulator上都不好使,所以改成了nsurlprotocol.
你知道怎么用cfnetwork监听网络请求么
CDuXZMAPgHp1q9ew
2014-06-05 19:13:44 +08:00
@nkwhya 不懂呢,我只试过替换js和css

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/115932

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX