CFURLCreateStringByAddingPercentEscapes is deprecated. Replacement?

851 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 answers

1
ios_dev On

use below code maybe its helped

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