Reputation: 1821
In one of my activity, I displayed a PDF using WebView on screen and tried to save this PDF using this code:
_pageSize = CGSizeMake(width, height);
NSString *newPDFName = [NSString stringWithFormat:@"%@", name];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:newPDFName];
UIGraphicsBeginPDFContextToFile(pdfPath, CGRectZero, nil);
NSLog(@"path=%@",pdfPath);
When I run this code in iOS simulator (using Xcode) and show the path and I opened this PDF file successfully in documents folder, but when I run this code in an iPhone, I got this path:
/var/mobile/Applications/0AF98361-C8DF-4C35-9E9F-EE48555185BC/Library/354746396.pdf
So where are PDF files stored in iPhone?
Upvotes: 0
Views: 130
Reputation: 1821
my coding is right but i will not find the pdf file.i will solve my problem.i will find my pdf file in device. there are two ways to find the pdf file. 1)install the iexplorer filemanager software.than open document folder. 2)connect your device in to the mac.select window menu and click the device in xcode.than after select your device name.select your app.
select show container.than after you can see the document folder....
Upvotes: 0
Reputation: 1214
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 367)];
webView.scalesPageToFit = YES;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF11.pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
}
Upvotes: 3
Reputation: 13025
"..InDomains(NSLibraryDirectory, NSUserDomainMask, YES);"
"../Library/354746396.pdf"
Your paths is looking in the NSLibraryDirectory
, it should be looking in the NSDocumentDirectory
like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
If still fail, try this code:
NSString *documents = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *savePath = [documents stringByAppendingPathComponent:@"filename.pdf"];
NSLog(@"savePath: %@", savePath);
Upvotes: 3