Interesting programming puzzle...
I failed to initialize error to nil, so the code below crashes.
NSString *query = [NSString stringWithFormat:@"http://mysite.com/getlatest.php?a=%@", aSuiteName];
NSURL *url = [NSURL URLWithString:query];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:10];
[request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if ( !data || error != nil ) {
NSLog(@"Error downlading %@", error); //CRASH
return NO;
}
My question is, how can I have my server return an error such that sendSynchronousRequest:returningResponse:error: actually receives an error, yet continues to download the data anyway? Some kind of non-fatal error which will result in error being initialized to an NSError object?
This is related to a similar conundrum where I've wanted to return status information without total failure before. So, although obscure, I'm interested to know if there is a technique for this.
Though this is a Cocoa question, I think the answer will be in php. Something like
<?php
header( set 503 error here );
return data;
?>