使用带有自定义URL协议的NSOutputStream outputStreamWithURL

我正在编写一个自定义URL协议(NSURLProtocol的子类)来处理需要特殊读写方式的本地文件。 阅读时没有问题:我可以成功创建一个URL,例如“my-funny-file-protocol:// ...”,所有的东西都可以正常工作。

当我尝试写入这种URL时,问题就出现了。 特别是,我需要使用NSOutputStream,所以我需要调用类似于:

NSString *urlString = [NSString stringWithFormat:@"my-funny-file-protocol://%@", path];
NSURL *url = [NSURL URLWithString:urlString];
NSOutputStream *writer = [NSOutputStream outputStreamWithURL:url append:NO];

没有异常提出,控制台上没有日志,但结果总是nil 。 如果我使用标准file: ,则相同的文件起作用file:协议:

NSString *urlString = [NSString stringWithFormat:@"file://%@", path];

为什么? 事实上,NSURLProtocol文档并没有很好地解释我的情况。 也许我错过了URLProtocol实现中的某些东西......但是什么?

提前谢谢了,

链接地址: http://www.djcxy.com/p/34835.html

上一篇: Using NSOutputStream outputStreamWithURL with a custom URLprotocol

下一篇: Why is my custom delegate method not being called?