How to save locally PDF or other files in iOS

▼魔方 西西 提交于 2020-01-05 19:46:08

问题


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 ?


回答1:


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];


来源:https://stackoverflow.com/questions/17082240/how-to-save-locally-pdf-or-other-files-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!