我正在开发阅读PDF并在iPhone和iPad上本地保存的功能。我正在构建iOS 6.1及更多版本,所以我对SDK没有任何限制。
所以,我想知道在本地(无论文件)写内容的最佳和最简单的解决方案是什么。
也许有人知道lib可以执行此功能吗?
答案 0 :(得分:10)
我在这里找到答案: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];