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ファイルが適切であることを知っているためpdf
、@interfaceで宣言されています。CGPDFDocumentRef pdf;
すべてが警告やエラーなしでコンパイルおよび実行されます。
ヘルプ!