iphone - int retVal = UIApplicationMain(argc, argv, nil, nil);尝试在 webView 中加载 pdf 时 EXC_BAD_ACCESS

标签 iphone pdf uiwebview exc-bad-access

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");
}

我尝试启用 NSAutoreleaseFreedObjectCheckEnabledNSZombieEnabledNSDebugEnabled 但在控制台中我什么也没得到。 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/

相关文章:

php - Tcpdf多重签名

iphone - 是否可以将哈希标记发送到 UIWebView 中的文件 url?

iphone - 在Windows 7中部署iPhone应用程序

ios - 有没有办法在 SFSafariViewController 中传递 headerField 参数?

java - PDFdictionary 和 unicode(和 Java)

objective-c - UIWebView iOS5 改变用户代理

ios - 具有自动布局的 UITableViewCell 中的动态大小的 UIWebView - 违反约束

iPhone:使用 Facebook 墙 API 发布消息时出现问题

iphone - UIWebView 加载数据和 iWork 文件

android - 我正在尝试使用 "Pdf creation library"在 flutter 应用程序中生成 pdf。在用其他语言生成 pdf 时会出现异常