Note that there are some explanatory texts on larger screens.

plurals
  1. POUIWebView displays locally stored document on simulator but not device
    text
    copied!<p>I have an issue where I'm trying to view a document (Word document, image, or video) that I have stored locally. I'm using UIWebView and on the Simulator it works perfectly, but on the device, it's a blank screen (no errors thrown in console). Here's my code to view the document:</p> <pre><code> UIWebView *newWebView; if (appDelegate.IS_IPAD) { newWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; } else { newWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; } newWebView.scalesPageToFit = YES; [self setWebView: newWebView]; [newWebView release], newWebView = nil; [[self webView] setDelegate: self]; [[self view] addSubview:[self webView]]; NSURL *nsURL = [NSURL fileURLWithPath:filePath isDirectory:NO]; [[self webView] loadRequest:[NSURLRequest requestWithURL:nsURL]]; </code></pre> <p>Here's how I'm saving the document locally before viewing. I do think the file is getting successfully saved on the device as it does on the simulator.</p> <pre><code> // Save the file on the device NSURL *contentUrl = [NSURL URLWithString:selectedContent.contentUrl]; NSString *fileName = [[contentUrl absoluteString] lastPathComponent]; NSString *homeDirectoryPath = NSHomeDirectory(); // Create the path NSString *unexpandedPath = [homeDirectoryPath stringByAppendingString:@"/MyApp/"]; NSString *folderPath = [NSString pathWithComponents:[NSArray arrayWithObjects:[NSString stringWithString:[unexpandedPath stringByExpandingTildeInPath]], nil]]; NSString *unexpandedImagePath = [folderPath stringByAppendingFormat:@"/%@", fileName]; NSString *filePath = [NSString pathWithComponents:[NSArray arrayWithObjects:[NSString stringWithString:[unexpandedImagePath stringByExpandingTildeInPath]], nil]]; if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath isDirectory:NULL]) { [[NSFileManager defaultManager] createDirectoryAtPath:nil withIntermediateDirectories:NO attributes:nil error:nil]; } // Do the actual write of the file to the device NSData *fileData = [NSData dataWithContentsOfURL:myUrl]; // Create the file data reference [fileData writeToFile:filePath atomically:YES]; //Save the document to the home directory </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