CFURLCreateStringByAddingPercentEscapes()とCFURLCreateStringBy ReplacingPercentEscapesUsingEncoding()は、in ios 9から破棄する.0

2421 ワード

CFRURLCreateStringByAddingPercentEscapes()符号化参照リンク:https://github.com/tweetdeck-archive/TDOAuth/issues/16
CF_EXPORT
CFStringRef CFURLCreateStringByAddingPercentEscapes(CFAllocatorRef
 allocator, CFStringRef originalString, CFStringRef charactersToLeaveUnescaped, 
CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding 
encoding) CF_DEPRECATED(10_0, 10_11, 2_0, 9_0, 
"Use [NSString stringByAddingPercentEncodingWithAllowedCharacters:] 
instead, which always uses the recommended UTF-8 encoding, 
and which encodes for a specific URL component or 
subcomponent (since each URL component or subcomponent has different rules for what characters are valid).");

C F r u r L C r e a t e S t e S t i n g B y R p l a c i n g PercentEscapesUsingEncoding()デコードリファレンスリンク:https://github.com/futuretap/InAppSettingsKit/issues/359
CF_EXPORT
CFStringRef CFURLCreateStringByReplacingPercentEscapesUsingEncoding
(CFAllocatorRef allocator, CFStringRef origString,
 CFStringRef charsToLeaveEscaped, CFStringEncoding encoding)
 CF_DEPRECATED(10_0, 10_11, 2_0, 9_0, "
Use [NSString stringByRemovingPercentEncoding] or 
CFURLCreateStringByReplacingPercentEscapes() instead, 
which always uses the recommended UTF-8 encoding.");

deprecated in iOS 9.0、廃棄されます
新しい使い方を変えて、ルールは自分でやります.url文字列に特殊な機能を持つ特殊文字の文字列、または中国語文字をパラメータとして渡す場合は、特殊記号のあるURLをencodeで処理する必要があります(特殊文字をトランスコードします)
// 
+(NSString*)encodeString:(NSString*)uncodeString
{
//    return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) uncodeString,NULL,(CFStringRef) @"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8));
    
    return (NSString *)CFBridgingRelease((__bridge CFTypeRef _Nullable)([[uncodeString description] stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"!*'();:@&=+$,/?%#[]"] invertedSet]]));
}
// 
+(NSString*)decodeString:(NSString*)decodeString
{
//    return (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,(__bridge CFStringRef)decodeString,CFSTR(""),CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
   
    return (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, (CFStringRef)decodeString, CFSTR("")));
}