作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这已弃用“stringByAddingPercentEscapesUsingEncoding”,我想用更新一替换这一行。
NSString *encodedString = [modalData.imageURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
最佳答案
尝试下面的代码行:
NSString *encodedString = [modalData.imageURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
stringByAddingPercentEncodingWithAllowedCharacters:
Returns a new string made from the receiver by replacing all characters not in the specified set with percent encoded characters.
字符集被传递给 - stringByAddingPercentEncodingWithAllowedCharacters
:
+ (NSCharacterSet *)URLUserAllowedCharacterSet;
+ (NSCharacterSet *)URLPasswordAllowedCharacterSet;
+ (NSCharacterSet *)URLHostAllowedCharacterSet;
+ (NSCharacterSet *)URLPathAllowedCharacterSet;
+ (NSCharacterSet *)URLQueryAllowedCharacterSet;
+ (NSCharacterSet *)URLFragmentAllowedCharacterSet;
引用:https://developer.apple.com/reference/foundation/nsstring/1411946-stringbyaddingpercentencodingwit
关于objective-c - stringByAddingPercentEscapesUsingEncoding 弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42529509/
我是一名优秀的程序员,十分优秀!