【发布时间】:2014-05-03 23:08:23
【问题描述】:
我正在尝试通过模拟器从 Parse 中提取 PDF 文件,并在单击我的应用程序上的按钮时将其保存到我的桌面上。问题是无论我做什么文件都不会出现在桌面或其他任何地方。我正在为我的下载按钮使用这种方法
-(void) Savefile {
NSFileManager *filemanager = [NSFileManager defaultManager];
[self.downloadfile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (error) {
}
else if (data) {
[filemanager createFileAtPath:@"file:///Users/Danny/Desktop" contents:data attributes:nil];
[data writeToFile:@"file:///Users/Danny/Desktop" atomically:NO ];
NSLog(@"Downloading file...");
}
}];
}
downloadFile 是一个 PFFile 属性,当我通过 segue 移动它时,它存储我的 PDF 文件的索引。它的声明如下:
@property (retain,nonatomic) PFFile * downloadfile;
这是转场:
detailVC.downloadfile=[[PDFArray objectAtIndex:indexPath.row]objectForKey:@"PDFFile"];
无法将其保存到桌面。
【问题讨论】:
-
忽略 iOS 应用程序无法访问其沙箱外文件的重要问题,请注意
writeToFile:和createFileAtPath:方法采用文件路径,而不是文件 URL。摆脱领先的file://。并摆脱对createFileAtPath:contents:attributes:的呼叫。您只需致电writeToFile:。 -
@rmaddy 所以我必须在沙箱内。有没有办法在侧面板上显示资源?还是看不到文件?
标签: ios arrays parsing pdf save