我的应用程序包中有文件test.pdf
。我在 iPhone Simulator (iPad) 中运行测试,但无法填充 CGPDFDocumentRef。我是疯了还是怎么了?!?
这是专门为此(ViewController 类)制作的示例应用程序中的一段代码:
- (void)viewDidLoad {
[super viewDidLoad];
// below code to show files in app bundle...
NSString *path = [[NSBundle mainBundle] resourcePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = [[NSError alloc] init];
NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];
//just to make sure the file is there : (test.pdf)
for (NSString *ts in directoryAndFileNames) {
NSLog(ts); // NSLog confirms the file is there
}
//Function below is supposed to create the CDPDFDocumentRef
[self updatePageRef]; // try to get the CGPDFDocumentRef
}
-(BOOL)updatePageRef {
NSLog(@"Updating PAGE");
NSString *pdfStringURL = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfStringURL];
NSLog([pdfURL path]); // this is good
NSLog(@"File Exists = %d", [[NSFileManager defaultManager] fileExistsAtPath:pdfStringURL]); // this gives me 1 (YES)
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
//from here on the pdf is nil??????????!!!!!!!!!!!!!
if (pdf && CGPDFDocumentGetNumberOfPages(pdf) > 0) {
return YES;
}
return NO;
}
以上pdf
是在@interface 中声明的,因为CGPDFDocumentRef pdf;
我知道PDF 文件很好,因为我已在“预览”中成功打开它。
一切都编译并运行,没有任何警告或错误。
帮助!