I a, saving a pdf file from the web locally and then loading it in a webView
. In iOS 4.0 and 4.1, it gives me BAD_ACCESS error while in iOS 4.2 and 4.3 it works fine.
This is the code I am using:
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");
}
I tried to enable NSAutoreleaseFreedObjectCheckEnabled
, NSZombieEnabled
and NSDebugEnabled
but in the console I get nothing.
Xcode just stops at that line:
int retVal = UIApplicationMain(argc, argv, nil, nil);
and states EXC_BAD_ACCESS
I do not have any idea what it could be and where to look next.
EDIT: I forgot to mention that if I comment the following line out it obviously doesn't crash because nothing is loaded into the webView.
[webView loadData:pdfFile MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
Try commenting out all the release
statements as a start... if the crash goes away, start narrowing down which one is causing the problem. Also: you should really study autorelease, because in a lot of cases you are retaining unnecessarily in the code above.
If that doesn't work, try commenting out pieces of your code bit by bit to figure out where it is really blowing up (obviously NOT where XCode shows).