Showing posts with label iOS4. Show all posts
Showing posts with label iOS4. Show all posts

Tuesday, June 22, 2010

Different behaviour in iOS4 for NSError and NSURLConnection

After running some of our apps now on iOS4 we were surprised that there were much more crashes. This little code section is what caused the crashes:

NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:requestStr]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSURLResponse *response;
NSError *error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(error) {
NSLog(@"error: %@", [error localizedDescription]);
}

After hours of debugging we could narrow it down to the line of code that initialises the NSError. Setting it to nil did remove the crash. So make sure your code looks like this:

NSError *error = nil;

We are currently investigating more issues we have with code that ran perfectly fine in 3.x and now starts crashing with iOS4. The above line fixed approximately 80% of our problems.

Good luck making your apps ready for iOS4.