iOS OC URL转码

2019-12-24  本文已影响0人  机械师shijier

1.NSString 方法

stringByAddingPercentEncodingWithAllowedCharacters  需要传一个  NSCharacterSet  对象

如[NSCharacterSet  URLQueryAllowedCharacterSet]

URLFragmentAllowedCharacterSet "#%<>[\]^`{|}

URLHostAllowedCharacterSet      "#%/<>?@\^`{|}

URLPasswordAllowedCharacterSet  "#%/:<>?@[\]^`{|}

URLPathAllowedCharacterSet      "#%;<>?[\]^`{|}

URLQueryAllowedCharacterSet    "#%<>[\]^`{|}

URLUserAllowedCharacterSet      "#%/:<>?@[\]^`

2.  

let customAllowedSet = NSCharacterSet(charactersInString:"`#%^{}\"[]|\\<> ").invertedSet

NSString *urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];

上一篇下一篇

猜你喜欢

热点阅读