![](/img/trans.png)
[英]Objective-C - 'sendSynchronousRequest:returningResponse:error:' is deprecated: first deprecated in iOS 9.0
[英]Objective-C 'CFURLCreateStringByAddingPercentEscapes' is deprecated: first deprecated in iOS 9.0
我收到了这个警告:
'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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.