I a,从本地网络保存一个 pdf 文件,然后将其加载到 webView
中。在 iOS 4.0 和 4.1 中,它给我 BAD_ACCESS 错误,而在 iOS 4.2 和 4.3 中它工作正常。
这是我正在使用的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"press.pdf"];
filePath = [[NSURL fileURLWithPath:path]retain];
NSError *err =nil;
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { //if file already exists delete it
NSLog(@"file is already there !");
[[NSFileManager defaultManager] removeItemAtPath:path error:&err];
NSLog(@"error: %@",err);
}
[responseData writeToURL:filePath atomically:YES];
[responseData release];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSLog(@"file is there");
NSData *pdfFile = [[NSData alloc]initWithContentsOfFile:path ];
[webView loadData:pdfFile MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
[pdfFile release];
}
else{
NSLog(@"file not there");
}
我尝试启用 NSAutoreleaseFreedObjectCheckEnabled
、NSZombieEnabled
和 NSDebugEnabled
但在控制台中我什么也没得到。
Xcode 就停在该行:
int retVal = UIApplicationMain(argc, argv, nil, nil);
并声明EXC_BAD_ACCESS
我不知道它可能是什么以及下一步该去哪里。
编辑:我忘了提及,如果我注释掉以下行,它显然不会崩溃,因为 webView 中没有加载任何内容。
[webView loadData:pdfFile MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
最佳答案
尝试注释掉所有 release
语句作为开始...如果崩溃消失,请开始缩小导致问题的范围。另外:你应该真正研究自动释放,因为在很多情况下你在上面的代码中保留了不必要的内容。
如果这不起作用,请尝试一点一点地注释掉代码片段,以找出它真正崩溃的地方(显然不是 XCode 显示的地方)。
关于iphone - int retVal = UIApplicationMain(argc, argv, nil, nil);尝试在 webView 中加载 pdf 时 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6534982/