What am I missing here:
+ (id) JSONObjectWithData:(NSData *)data {
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 50000
//iOS < 5 didn't have the JSON serialization class
return [data objectFromJSONData]; //JSONKit
#else
NSError *jsonParsingError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParsingError];
return jsonObject;
#endif
}
I’m compiling on base SDK 5.0, deployment version is 4.0. When I run it on an iPhone 3G with 4.2.1 I get …..
dyld: Symbol not found: _OBJC_CLASS_$_NSJSONSerialization
Crash on startup….
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 50000is evaluated on compile time. If you compile your code with the iOS 5 SDK the condition will be false. And the NSJSONSerialization code will be used anyway.You should check if the
NSJSONSerializationclass exists. Like this: