【发布时间】:2011-09-30 12:51:27
【问题描述】:
在我的工作中,我只想在 iphone 设备中阅读下载的 PDF
起初,我尝试使用“bundleRoot”目录,它可以在模拟器上工作,但不能在设备上工作。现在,我只是在模拟器中测试 Document of Document 或 Cache。
How can I get a writable path on the iPhone?
看完上面的题目,
我尝试过使用文档目录或缓存目录。
这是我查找可写路径的代码
/**************************************************** ************************************/
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}
NSString *path_to_file = [cachePath stringByAppendingPathComponent:@"testing6.pdf"];
/**************************************************** ************************************/
我可以在这个目录中找到下载的文件并获取大小,但是我无法使用以下代码读取文件:
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
page = CGPDFDocumentGetPage(pdf, 1);
CGPDFPageRetain(page);
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
返回pageRect.size.width为0
我打印出下载和检索文件路径后也是:
/Users/ITDEV/Library/Application Support/iPhone Simulator/4.3.2/Applications/806ED359-70F8-4C07-996F-6AFC959B3FC7/Library/Caches/testing6.pdf
谁能帮帮我?
【问题讨论】:
标签: iphone objective-c caching document