GymotgM commented on issue #977: URL: https://github.com/apache/cordova-ios/issues/977#issuecomment-2050888195
Previous projects were intercepted through NSURLProtocol, but now NSURLProtocol no longer exists @dpogue + (BOOL)canInitWithRequest:(NSURLRequest*)theRequest { NSURL* theUrl = [theRequest URL]; if ([[theUrl absoluteString] hasPrefix:kEBCDVBundlePrefixes] || [[theUrl absoluteString] hasPrefix:kEBCDVFilePrefixes]) { return YES; } else { return [CDVURLProtocol canInitWithRequest:theRequest]; } } - (void)startLoading { NSURL* url = [[self request] URL]; if ([[url absoluteString] hasPrefix:kEBCDVBundlePrefixes] || [[url absoluteString] hasPrefix:kEBCDVFilePrefixes]) { NSString *scheme = url.scheme; NSString *fileName = url.host; NSString *filePath = nil; if ([scheme isEqualToString:kEBCDVBundlePrefixes]) { filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:nil]; } else { __block NSString *appId = nil; dispatch_sync(dispatch_get_main_queue(), ^{ UIViewController *currentVC = [Common currentViewController]; if ([currentVC isKindOfClass:[EBCDVViewController class]]) { appId = [(EBCDVViewController *)currentVC appId]; } }); filePath = [[Common getDocDirectoryOfApp:appId] stringByAppendingPathComponent:fileName]; } if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { [self sendResponseWithResponseCode:404 data:nil mimeType:nil]; return; } NSData *fileData = [NSData dataWithContentsOfFile:filePath]; if (!fileData) { [self sendResponseWithResponseCode:404 data:nil mimeType:nil]; return; } [self sendResponseWithResponseCode:200 data:fileData mimeType:nil]; return; } else { [super startLoading]; } } - (void)sendResponseWithResponseCode:(NSInteger)statusCode data:(NSData*)data mimeType:(NSString*)mimeType { if (mimeType == nil) { mimeType = @"text/plain"; } NSHTTPURLResponse* response = [[NSHTTPURLResponse alloc] initWithURL:[[self request] URL] statusCode:statusCode HTTPVersion:@"HTTP/1.1" headerFields:@{@"Content-Type" : mimeType}]; [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; if (data != nil) { [[self client] URLProtocol:self didLoadData:data]; } [[self client] URLProtocolDidFinishLoading:self]; } -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org