title: iOS how to insert a local file URL into NSURLConnection response data?
body: <p>I'm trying to modify a behavior of a webpage within my iOS app and make the in-page media player play a file from the local caches folder instead of fetching it from a web server. </p>
  
  <p>Below is my code that replaces the http:// video path with a local file path. The code does not work, giving me "Resource Temporary not available. Please try again" error message popup. <strong>Is it possible to have a web-based media player play file from a local disk using file URL?</strong> 
  I tried substituting these for the instanceURL, but they don't seem to work.</p>
  
  <pre><code>[fileURL path]
  [fileURL absolutePath]
  </code></pre>
  
  <p>I'm intercepting the request for the file and am parsing it to find out that the page is asking for a video file:</p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
      // An NSURLConnection delegate callback.  We pass this on to the client.
  {
  
  
      NSDictionary* decisionDictionary = [[RequestListener sharedInstance] shouldContinue:connection processRequestData:data];
  
      BOOL shouldContinue = [decisionDictionary[@"shouldContinue"] boolValue];
  
      if(shouldContinue == NO)
      {
          return;
      }else
      {
          NSData* d = data;
          //substitute fake data
          if(decisionDictionary[@"data"])
          {
              d = decisionDictionary[@"data"];
          }
  
          [[self client] URLProtocol:self didLoadData:d];
  
      }
  
  
  }
  </code></pre>
  
  <p>Within my shouldContinue method, I check if the video is present locally and modify the response data to create a path to a local video.</p>
  
  <pre><code>    NSString* path = [VideoDownloader localVideoPathForVideoID:videoID];
       NSURL* fileURL = [NSURL fileURLWithPath:path];
  
  DLog(@"url:%@",[fileURL absoluteString]);
       NSString* replacement = [NSString stringWithFormat:@"\"instanceUrl\":\"%@\"",[[fileURL absoluteURL] absoluteString]];
        DLog(@"replacement:%@",replacement);
        NSString* forgedResponse = [parts componentsJoinedByString:@","];
        NSData* forgedData = [forgedResponse dataUsingEncoding:NSUTF8StringEncoding];
        return @{@"shouldContinue":@(YES),@"data":forgedData};
  </code></pre>