iOs - Url encode

2 minuti di lettura
The stringByAddingPercentEscapesUsingEncoding function doesn't translate all characters for URL encoding.

To encode all characters I use the CFURLCreateStringByAddingPercentEscapes function as follow:


- (NSString*) encodeUrlString:(NSString*)unencodedString {
return (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)unencodedString,NULL,(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", kCFStringEncodingUTF8 );
}