Skip to content

Commit f50d314

Browse files
committed
Use newer percent encoding method where available
Checks deployment target for compatibility Closes #416
1 parent 0f50725 commit f50d314

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

JSONModel/JSONModelNetworking/JSONHTTPClient.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,20 @@ +(NSString*)urlEncode:(id<NSObject>)value
120120
}
121121

122122
NSAssert([value isKindOfClass:[NSString class]], @"request parameters can be only of NSString or NSNumber classes. '%@' is of class %@.", value, [value class]);
123-
123+
124+
NSString *str = (NSString *)value;
125+
126+
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_0 || __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_9
127+
return [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
128+
129+
#else
124130
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
125131
NULL,
126-
(__bridge CFStringRef) value,
132+
(__bridge CFStringRef)str,
127133
NULL,
128134
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
129135
kCFStringEncodingUTF8));
136+
#endif
130137
}
131138

132139
#pragma mark - networking worker methods

0 commit comments

Comments
 (0)