ikevin8me ikevin8me - 1 year ago 230
iOS Question

CFURLCreateStringByAddingPercentEscapes is deprecated in iOS 9, how do I use "stringByAddingPercentEncodingWithAllowedCharacters"

I have the following code:

return (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(";:@&=+$,/?%#[]"), kCFStringEncodingUTF8);

Xcode says it is deprecated in iOS 9. So, how do I use stringByAddingPercentEncodingWithAllowedCharacters ?


Answer Source

try this

NSString *value = @"<url>";
value = [value stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];