CFURLCreateStringByAddingPercentEscapes is deprecated. Replacement?

890 Views Asked by At

Here is my code

CFStringRef escapedStr;

  escapedStr = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                       originalString,
                                                       leaveUnescaped,
                                                       kCharsToForceEscape,
                                                       kCFStringEncodingUTF8);

The Error is:

CFURLCreateStringByAddingPercentEscapes is deprecated in ios 9.0, use stringByAddingPercentEncodingWithAllowedCharacters which always uses recommended UTF-8 settings.

Could somebody help with how to replace CFURLCreateStringByAddingPercentEscapes with stringByAddingPercentEncodingWithAllowedCharacters in above code.

1

There are 1 best solutions below

1
On

use below code maybe its helped

CFStringRef escapedStr;
escapedStr = (__bridge CFStringRef)([str stringByAddingPercentEncodingWithAllowedCharacters:[kCFAllocatorDefault,originalString,leaveUnescaped,kCharsToForceEscape,kCFStringEncodingUTF8]]);// here str is your NSString