iOs - Url encode
2 min read
The stringByAddingPercentEscapesUsingEncoding function doesn't translate all characters for URL encoding.
To encode all characters I use the CFURLCreateStringByAddingPercentEscapes function as follow:
To encode all characters I use the CFURLCreateStringByAddingPercentEscapes function as follow:
- (NSString*) encodeUrlString:(NSString*)unencodedString {
return (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)unencodedString,NULL,(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", kCFStringEncodingUTF8 );
}