cem*_*nds 5 iphone objective-c nsurlconnection nsurlprotocol
我尝试在我的自定义NSURLProtocol中返回NSURLResponse的子类的对象,但似乎返回的响应总是由普通的NSURLResponse交换.
这是我返回自定义TestURLResponse的NSURLProtocol的一部分:
TestURLResponse* response = [[[TestURLResponse alloc] initWithURL: [[self request] URL]
MIMEType: @"text/plain"
expectedContentLength: 4
textEncodingName:@"UTF-8"]
autorelease];
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
[self.client URLProtocol:self didLoadData: [@"Test" dataUsingEncoding:NSUTF8StringEncoding]];
[self.client URLProtocolDidFinishLoading: self];
Run Code Online (Sandbox Code Playgroud)
当我与这个协议读的东西我希望得到类型TestURLResponse的反应,但在下面的代码我总是得到一个NSURLResponse:
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"test://test"]];
NSURLResponse* response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *className = NSStringFromClass([response class]);
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:className message:className delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
Run Code Online (Sandbox Code Playgroud)
整个测试项目可以在下载
现在我不知道我做错了什么或是否有什么东西坏了.NSURLProtocol的文档说明
协议实现者可能希望创建自定义的可变NSURLResponse类以提供协议特定信息.
但在我看来,这根本不起作用.
| 归档时间: |
|
| 查看次数: |
1524 次 |
| 最近记录: |