gpt4 book ai didi

ios - Objective-C 'CFURLCreateStringByAddingPercentEscapes' 已弃用 : first deprecated in iOS 9. 0

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:32 26 4
gpt4 key购买 nike

我收到了这个警告:

'CFURLCreateStringByAddingPercentEscapes' is deprecated: first deprecated in iOS 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).

在这一行:

return (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding));

我试图用谷歌搜索解决方案,但我什么都不懂。请帮忙。

我尝试了以下方法:

return [NSString stringByAddingPercentEncodingWithAllowedCharacters:(NULL, (CFStringRef)self, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", CFStringConvertNSStringEncodingToEncoding(encoding))];

并收到这个新警告:

Class method '+stringByAddingPercentEncodingWithAllowedCharacters:' not found (return type defaults to 'id')

Expression result unused

最佳答案

好的,我来试试:

- (NSString *)escaped
{
#if (TARGET_OS_MAC && (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9))
NSString * encodedString = (NSString *)
CFURLCreateStringByReplacingPercentEscapes(
NULL,
(CFStringRef)self,
NULL);
#else
NSString * encodedString = (NSString *)
CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)self,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );
#endif
return encodedString;
}

关于ios - Objective-C 'CFURLCreateStringByAddingPercentEscapes' 已弃用 : first deprecated in iOS 9. 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32907840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com