GymotgM opened a new issue, #1420:
URL: https://github.com/apache/cordova-ios/issues/1420

   <!------------^ Click "Preview" for a nicer view! -->
   
   Apache Cordova uses GitHub Issues as a feature request and bug tracker 
_only_.
   For usage and support questions, please check out the resources below. 
Thanks!
   
   ---
   
   You can get answers to your usage and support questions about **Apache 
Cordova** on:
   
   * Slack Community Chat: https://cordova.slack.com (you can sign-up at 
https://s.apache.org/cordova-slack)
   * StackOverflow: https://stackoverflow.com/questions/tagged/cordova using 
the tag `cordova`
   
   + (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];
   }
   
   If you are using a tool that uses Cordova internally, like e.g. Ionic, check 
their support channels:
   
   * **Ionic Framework**
     * [Ionic Community Forum](https://forum.ionicframework.com/)
     * [Ionic Worldwide Slack](https://ionicworldwide.herokuapp.com/)
   * **PhoneGap**
     * [PhoneGap Developer 
Community](https://forums.adobe.com/community/phonegap)
   


-- 
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.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

Reply via email to