Since upgrading to iOS 9.1 my custom NSURLProtocol
, won't invoke -(void)startLoading
anymore. Has anyone else experienced this ?
Everything worked fine on iOS 8 ...
Code:
@implementation RZCustomProtocol
@dynamic request;
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
if ([request.URL.scheme isEqualToString:@"imsweb"]) {
NSLog(@"%@", @"YES");
return YES;
}
return NO;
}
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
return request;
}
+ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b {
return [super requestIsCacheEquivalent:a toRequest:b];
}
- (void)startLoading {
NSLog(@"STARTLOADING: %@", [self.request.URL absoluteString]);
NSString *filename = [[self.request.URL lastPathComponent] stringByDeletingPathExtension];
NSLog(@"%@", filename);
NSString *videoUrl = [[NSBundle mainBundle] pathForResource:filename ofType:@"mp4"];
NSData *video = [NSData dataWithContentsOfFile:videoUrl];
NSLog(@"%lu", (unsigned long)video.length);
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.request.URL
statusCode:200 HTTPVersion:nil headerFields:@{
@"Content-Length": [NSString stringWithFormat:@"%lu", (unsigned long)video.length],
@"Content-Type": @"video/mp4",
}];
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
[self.client URLProtocol:self didLoadData:video];
[self.client URLProtocolDidFinishLoading:self];
}
- (void)stopLoading {
NSLog(@"STOPLOADING: %@", [self.request.URL absoluteString]);
}