Я смог решить это сам.Метод PhoneGap fileEntry.toURI () возвращает URL-адрес, похожий на тот, который я включил в исходную запись:
file://localhost/Users/{username}/Library/Application Support/iPhone Simulator/5.1/Applications/5D8EDAB7-4BB7-409E-989D-250A84B37877/Documents/{filename}
После того, как вы перепрыгнули через несколько циклов, чтобы убедиться, что URL-адрес файла экранирован и относительно каталога документов приложения,полученный URL, который успешно загружается, выглядит примерно так:
file:///Users/{username}/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/B50682DD-AE6C-4015-AE61-3879576A4CB7/Documents/{relativeUri}
Просто немного по-другому.Чтобы исправить это, возможно, не для каждого случая, но по крайней мере для моего, я изменил метод loadURL в ChildBrowserViewController для поиска URL-адреса файла и удаления абсолютного содержимого, оставляя URL-адрес относительно каталога документов приложения.Затем я использовал NSFileManager, чтобы помочь создать URL, который будет работать.Я относительно новичок в разработке для iOS, так что, возможно, есть лучший способ сделать это.Добро пожаловать на вход.Вот код:
- (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:&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];
}
...
}