Quartz 2D 프로그래밍 가이드로 이동 한 후 PDF 파일의 내용을 읽을 수있는 코드를 함께 작성했습니다. PDF 스캐너 부분에서는 실패했습니다. 스캐너를 출시 할 때 다음 오류로 인해 응용 프로그램이 다운됩니다 :iOS : PDF 파일의 내용 읽기
avi(2282,0x3de7bb88) malloc: *** error for object 0x693f7c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
전자 메일 첨부 파일을 통해 PDF 파일을 여는 중입니다. 적어도 페이지 수를 얻을 수 있기 때문에 파일을 인식하고 있다는 것을 알고 있습니다. 누군가 내 코드를보고 내 오류가 발생한 곳을 볼 수 있습니까? 감사.
- (void) readPDFFile:(NSURL *)PDFURL {
//make a pdf document and point it to the url of our pdf file
CGPDFDocumentRef pdfDocument;
pdfDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)(PDFURL));
//release the url
CFRelease((__bridge CFTypeRef)(PDFURL));
if (pdfDocument) {
//get page count
int pageCount = CGPDFDocumentGetNumberOfPages (pdfDocument);
//
if (pageCount > 0) {
//set up operator table
CGPDFOperatorTableRef pdfOpTable;
pdfOpTable = CGPDFOperatorTableCreate();
//call backs for Op Table
CGPDFOperatorTableSetCallback (pdfOpTable, "MP", &op_MP);
CGPDFOperatorTableSetCallback (pdfOpTable, "DP", &op_DP);
CGPDFOperatorTableSetCallback (pdfOpTable, "BMC", &op_BMC);
CGPDFOperatorTableSetCallback (pdfOpTable, "BDC", &op_BDC);
CGPDFOperatorTableSetCallback (pdfOpTable, "EMC", &op_EMC);
for(int i=0; i<pageCount; i++) {
//set up
CGPDFPageRef thisPage;
CGPDFScannerRef pdfScanner;
CGPDFContentStreamRef thisContentStream;
//get the page
thisPage = CGPDFDocumentGetPage (pdfDocument, i + 1);
//get the page content stream
thisContentStream = CGPDFContentStreamCreateWithPage (thisPage);
//create a pdf scanner using our previously created table and callbacks
pdfScanner = CGPDFScannerCreate (thisContentStream, pdfOpTable, NULL);
//scan the pdf file
CGPDFScannerScan (pdfScanner); //-->call backs happen here
//release everything
CGPDFPageRelease (thisPage);
/*CGPDFScannerRelease (pdfScanner);
CGPDFContentStreamRelease (thisContentStream);*/
}
}
}
//release the pdf document
CGPDFDocumentRelease(pdfDocument);
}
static void op_MP (CGPDFScannerRef s, void *info) {
const char *name;
if (!CGPDFScannerPopName(s, &name))
return;
NSLog(@"MP /%s\n", name);
}
static void op_DP (CGPDFScannerRef s, void *info) {
const char *name;
if (!CGPDFScannerPopName(s, &name))
return;
NSLog(@"DP /%s\n", name);
}
static void op_BMC (CGPDFScannerRef s, void *info) {
const char *name;
if (!CGPDFScannerPopName(s, &name))
return;
NSLog(@"BMC /%s\n", name);
}
static void op_BDC (CGPDFScannerRef s, void *info) {
const char *name;
if (!CGPDFScannerPopName(s, &name))
return;
NSLog(@"BDC /%s\n", name);
}
static void op_EMC (CGPDFScannerRef s, void *info) {
const char *name;
if (!CGPDFScannerPopName(s, &name))
return;
NSLog(@"EMC /%s\n", name);
}
편집 : PDFURL은이 프로세스에서 비롯됩니다. 사용자는 앱을 사용하여 이메일에 첨부 된 PDF 파일을 열려고합니다. AppDelegate.m에서 : viewcontroller.m에서
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
/* NSLog(@"Open URL:\t%@\n"
"From source:\t%@\n"
"With annotation:%@",
url, sourceApplication, annotation);*/
NSMutableDictionary* userData = [[NSMutableDictionary alloc] init];
[userData setObject:@"Read PDF" forKey:@"Action"];
[userData setObject:url forKey:@"File Path"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"theMessenger" object:self userInfo: userData];
//NSString *filepath = [url path];
//...
return YES;
}
- (void) receiveNotification:(NSNotification*) notification {
...
} else if ([strAction isEqualToString:@"Read PDF"]) {
NSURL* documentURL = [[notification userInfo] objectForKey:@"File Path"];
[self readPDFFile:documentURL];
}
...
편집 : 나는이 페이지의 응용 프로그램을 해제하지 않으면 여전히 충돌 :
libobjc.A.dylib`objc_release : 0x3be89f20 : CMP의 R0, # 0은 0x3be89f22 : bxeq의 LR 0x3be89f26 : 그것은 0x3be89f24 당량 선량률 (R1)을, [R0] 0x3be89f28 : MOVS R2, # 2 0x3be89f2a : 선량률 R1 [R1 # 16] 0x3be89f2c : BFI R1, R2, # 0, # 2 0x3be89f30 : LDRB의 R1, [R1] 0x3be89f32, R1, # 2 0x3be89f36 tst.w : BNE 0x3be89f3e; objc_release + 30 0x3be89f38 : movs r1, # 0 0x3be89f3a : b.w 0x3be981c0; - [NSObject의 릴리스] 0x3be89f3e : MOVW R1, # 19326 0x3be89f42 : MOVT의 R1, # 507 0x3be89f46, R1 추가 PC 0x3be89f48 : 선량률 R1 [R1] 0x3be89f4a : 0x3be875a0 b.w; objc_msgSend 0x3be89f4e는 :
여기서'PDFURL '은 어디에서 왔습니까? 당신은 당신의 방법 안에 풀어 놓아야한다고 확신합니까? –
@Martin - OP – PruitIgoe
하단의 편집 참조 호출 메서드에서 'documentURL'을 소유하지 않으므로'PDFURL'을 해제하면 안됩니다. –