2

I'm writing a custom URL protocol (subclass of NSURLProtocol) to deal with local files that need a special way of reading and writing. No problem when reading: I can successfully create an URL like -for example- "my-funny-file-protocol://...." and all the things work fine.

The problem arises when I try to write to this kind of URL's. In particular, I need to use an NSOutputStream, so I need to call something like:

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

No exception raises, no logs on the console but the result is always nil. The same file works, if I use a standard file: protocol:

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

Why? In fact the NSURLProtocol documentation does not explain well my case. Perhaps I'm missing someting in my URLProtocol implementation... but what?

Many thanks in advance,

Rob

roberto.buratti
  • 2,487
  • 1
  • 16
  • 10

0 Answers0