stringByAddingPercentEncodingWithAllowedCharacters 需要传一个 NSCharacterSet 对象(关于 NSCharacterSet 这篇 文章说的很好)
如[NSCharacterSet URLQueryAllowedCharacterSet]
URLFragmentAllowedCharacterSet "#%<>[\]^`{|} URLHostAllowedCharacterSet "#%/<>?@\^`{|} URLPasswordAllowedCharacterSet "#%/:<>?@[\]^`{|} URLPathAllowedCharacterSet "#%;<>?[\]^`{|} URLQueryAllowedCharacterSet "#%<>[\]^`{|} URLUserAllowedCharacterSet "#%/:<>?@[\]^`(2)网络访问请求:中文空格字符解码
stringByRemovingPercentEncoding ---- xcode7可能会提示要将stringByAddingPercentEscapesUsingEncoding替换成此方法,要根据是否是解码来区分
代替 stringByAddingPercentEscapesUsingEncoding
let customAllowedSet = NSCharacterSet(charactersInString:"`#%^{}\"[]|\\<> ").invertedSet NSString *urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];