V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nkwhya
V2EX  ›  程序员

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

  •  
  •   nkwhya · 2014-06-05 14:13:23 +08:00 · 3377 次点击
    这是一个创建于 3606 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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.)
    3 条回复    2014-06-05 19:13:44 +08:00
    wujichao
        1
    wujichao  
       2014-06-05 15:31:54 +08:00   ❤️ 1
    试试重载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
        2
    nkwhya  
    OP
       2014-06-05 16:04:36 +08:00   ❤️ 1
    @wujichao 这个方法也试过了,video在simulator上都不好使,所以改成了nsurlprotocol.
    你知道怎么用cfnetwork监听网络请求么
    wujichao
        3
    wujichao  
       2014-06-05 19:13:44 +08:00
    @nkwhya 不懂呢,我只试过替换js和css
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5291 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:49 · PVG 15:49 · LAX 00:49 · JFK 03:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.