Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was able to solve this myself. The PhoneGap fileEntry.toURI() method returns a URL something like what I included in my original post:</p> <pre><code>file://localhost/Users/{username}/Library/Application Support/iPhone Simulator/5.1/Applications/5D8EDAB7-4BB7-409E-989D-250A84B37877/Documents/{filename} </code></pre> <p>After jumping through some hoops to ensure the file URL was escaped and relative to the app's documents directory, the resulting URL which loads successfully looks something like this:</p> <pre><code>file:///Users/{username}/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/B50682DD-AE6C-4015-AE61-3879576A4CB7/Documents/{relativeUri} </code></pre> <p>Just a little different. To fix this, maybe not for every case but at least for mine, I modified the loadURL method in the ChildBrowserViewController to look for a file URL and strip out the absolute stuff, leaving a URL relative to the app's documents directory. Then I used NSFileManager to help build up a URL that would work. I'm relatively new to iOS development, so maybe there's a better way to do this. Welcome the input. Here's the code:</p> <pre><code>- (void)loadURL:(NSString*)url { ... else if([url hasPrefix:@"file://"]) { NSError *error = NULL; //Create the regular expression to match against NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"file://.*/Documents/" options:NSRegularExpressionCaseInsensitive error:&amp;error]; // Create the new string by replacing the matching of the regex pattern with the template pattern(empty string) NSString *relativeUri = [regex stringByReplacingMatchesInString:url options:0 range:NSMakeRange(0, [url length]) withTemplate:@""]; NSLog(@"New string: %@", relativeUri); NSURL *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; NSURL *url = [documentsDirectory URLByAppendingPathComponent:relativeUri]; NSLog(@"New string: %@", url); NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; } ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload