mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-31 15:37:01 +00:00
Remove JSON pre iOS5 lib support, always use NSJsonSerialization
This commit is contained in:
parent
a54e20b48b
commit
eb05becb5b
@ -748,7 +748,7 @@
|
|||||||
|
|
||||||
NSError *error = NULL;
|
NSError *error = NULL;
|
||||||
|
|
||||||
NSDictionary *feedDict = (NSDictionary *)bit_parseJSON(responseString, &error);
|
NSDictionary *feedDict = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
|
||||||
|
|
||||||
// server returned empty response?
|
// server returned empty response?
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
NSString *bit_URLEncodedString(NSString *inputString);
|
NSString *bit_URLEncodedString(NSString *inputString);
|
||||||
NSString *bit_URLDecodedString(NSString *inputString);
|
NSString *bit_URLDecodedString(NSString *inputString);
|
||||||
NSComparisonResult bit_versionCompare(NSString *stringA, NSString *stringB);
|
NSComparisonResult bit_versionCompare(NSString *stringA, NSString *stringB);
|
||||||
id bit_parseJSON(NSString *inputString, NSError **error);
|
|
||||||
NSString *bit_encodeAppIdentifier(NSString *inputString);
|
NSString *bit_encodeAppIdentifier(NSString *inputString);
|
||||||
|
|
||||||
/* UIImage helpers */
|
/* UIImage helpers */
|
||||||
|
@ -76,83 +76,6 @@ NSComparisonResult bit_versionCompare(NSString *stringA, NSString *stringB) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse JSON depending on the available framework
|
|
||||||
id bit_parseJSON(NSString *inputString, NSError **error) {
|
|
||||||
error = nil;
|
|
||||||
|
|
||||||
if (!inputString)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
id feedResult = nil;
|
|
||||||
|
|
||||||
#if BW_NATIVE_JSON_AVAILABLE
|
|
||||||
feedResult = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
|
|
||||||
#else
|
|
||||||
id nsjsonClass = NSClassFromString(@"NSJSONSerialization");
|
|
||||||
SEL nsjsonSelect = NSSelectorFromString(@"JSONObjectWithData:options:error:");
|
|
||||||
SEL sbJSONSelector = NSSelectorFromString(@"JSONValue");
|
|
||||||
SEL jsonKitSelector = NSSelectorFromString(@"objectFromJSONStringWithParseOptions:error:");
|
|
||||||
SEL yajlSelector = NSSelectorFromString(@"yajl_JSONWithOptions:error:");
|
|
||||||
|
|
||||||
if (nsjsonClass && [nsjsonClass respondsToSelector:nsjsonSelect]) {
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[nsjsonClass methodSignatureForSelector:nsjsonSelect]];
|
|
||||||
invocation.target = nsjsonClass;
|
|
||||||
invocation.selector = nsjsonSelect;
|
|
||||||
NSData *jsonData = [inputString dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
|
|
||||||
if (!jsonData)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
[invocation setArgument:&jsonData atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
|
|
||||||
NSUInteger readOptions = kNilOptions;
|
|
||||||
[invocation setArgument:&readOptions atIndex:3];
|
|
||||||
[invocation setArgument:&error atIndex:4];
|
|
||||||
[invocation invoke];
|
|
||||||
[invocation getReturnValue:&feedResult];
|
|
||||||
} else if (jsonKitSelector && [inputString respondsToSelector:jsonKitSelector]) {
|
|
||||||
// first try JSONkit
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[inputString methodSignatureForSelector:jsonKitSelector]];
|
|
||||||
invocation.target = inputString;
|
|
||||||
invocation.selector = jsonKitSelector;
|
|
||||||
int parseOptions = 0;
|
|
||||||
[invocation setArgument:&parseOptions atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
|
|
||||||
[invocation setArgument:&error atIndex:3];
|
|
||||||
[invocation invoke];
|
|
||||||
[invocation getReturnValue:&feedResult];
|
|
||||||
} else if (sbJSONSelector && [inputString respondsToSelector:sbJSONSelector]) {
|
|
||||||
// now try SBJson
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[inputString methodSignatureForSelector:sbJSONSelector]];
|
|
||||||
invocation.target = inputString;
|
|
||||||
invocation.selector = sbJSONSelector;
|
|
||||||
[invocation invoke];
|
|
||||||
[invocation getReturnValue:&feedResult];
|
|
||||||
} else if (yajlSelector && [inputString respondsToSelector:yajlSelector]) {
|
|
||||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[inputString methodSignatureForSelector:yajlSelector]];
|
|
||||||
invocation.target = inputString;
|
|
||||||
invocation.selector = yajlSelector;
|
|
||||||
|
|
||||||
NSUInteger yajlParserOptions = 0;
|
|
||||||
[invocation setArgument:&yajlParserOptions atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
|
|
||||||
[invocation setArgument:&error atIndex:3];
|
|
||||||
|
|
||||||
[invocation invoke];
|
|
||||||
[invocation getReturnValue:&feedResult];
|
|
||||||
} else {
|
|
||||||
if (error != NULL)
|
|
||||||
*error = [[NSError errorWithDomain:kBITHockeyErrorDomain
|
|
||||||
code:HockeyAPIClientMissingJSONLibrary
|
|
||||||
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"You need a JSON Framework in your runtime for iOS4!", NSLocalizedDescriptionKey, nil]] retain];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (error != NULL) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
return feedResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *bit_encodeAppIdentifier(NSString *inputString) {
|
NSString *bit_encodeAppIdentifier(NSString *inputString) {
|
||||||
return (inputString ? bit_URLEncodedString(inputString) : bit_URLEncodedString([[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]));
|
return (inputString ? bit_URLEncodedString(inputString) : bit_URLEncodedString([[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]));
|
||||||
}
|
}
|
||||||
|
@ -559,8 +559,8 @@
|
|||||||
if ([responseData length]) {
|
if ([responseData length]) {
|
||||||
NSString *responseString = [[[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding: NSUTF8StringEncoding] autorelease];
|
NSString *responseString = [[[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding: NSUTF8StringEncoding] autorelease];
|
||||||
|
|
||||||
NSDictionary *feedDict = (NSDictionary *)bit_parseJSON(responseString, &error);
|
NSDictionary *feedDict = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
|
||||||
|
|
||||||
// server returned empty response?
|
// server returned empty response?
|
||||||
if (![feedDict count]) {
|
if (![feedDict count]) {
|
||||||
[self reportError:[NSError errorWithDomain:kBITUpdateErrorDomain
|
[self reportError:[NSError errorWithDomain:kBITUpdateErrorDomain
|
||||||
@ -816,7 +816,8 @@
|
|||||||
BITHockeyLog(@"INFO: Received API response: %@", responseString);
|
BITHockeyLog(@"INFO: Received API response: %@", responseString);
|
||||||
|
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
id json = bit_parseJSON(responseString, &error);
|
NSDictionary *json = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
|
||||||
|
|
||||||
self.trackerConfig = (([self checkForTracker] && [[json valueForKey:@"tracker"] isKindOfClass:[NSDictionary class]]) ? [json valueForKey:@"tracker"] : nil);
|
self.trackerConfig = (([self checkForTracker] && [[json valueForKey:@"tracker"] isKindOfClass:[NSDictionary class]]) ? [json valueForKey:@"tracker"] : nil);
|
||||||
|
|
||||||
if (![self isAppStoreEnvironment]) {
|
if (![self isAppStoreEnvironment]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user