Skip to main content

Posts

Showing posts from September, 2015

Percent Escape the reserved Characters in URI

URI encoding need to be done when performing network API calls based on RFC 3986. In order to encode any character, the following native method can be used: [uriString stringByAddingPercentEncodingWithAllowedCharacters : [ NSCharacterSet URLQueryAllowedCharacterSet ] ] But the above method is not compliant with RFC3986 and it does not encode the reserved characters like "!*'();:@&=+$,/?%#[]". Hence, the following method can be used for percent encoding the specific reserved characters. ((NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef) string, NULL,  CFSTR("!*'();:@&=+$,/?%#[]"), encoding))); }