Kevin Machado
Kevin Machado

Reputation: 4187

How to save locally PDF or other files in iOS

I'm developing functions to read PDF and Save it locally on iPhone and iPad. I'm building this to iOS 6.1 and more, so I don't have any constraint for the SDK.

So, I wanna know what's the best and simple solution to write contents locally (whatever file).

Perhaps somebody knows a lib to do this functionality ?

Upvotes: 1

Views: 9688

Answers (1)

Kevin Machado
Kevin Machado

Reputation: 4187

I found the answer here : Save your app data with NSCoding and NSFileManager

NSData *dataPdf = [NSData dataWithContentsOfURL:pdfOnline.url];

//Get path directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//Create PDF_Documents directory
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"PDF_Documents"];
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];

NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"**PUT FILENAME YOU WANT**"];

[dataPdf writeToFile:filePath atomically:YES];

Upvotes: 10

Related Questions