stringByAddingPercentEscapesUsingEncoding(只对 `#%^{}[]|"<> 加空格共14个字符编码,不包括”&?”等符号), ios9将淘汰,建议用stringByAddingPercentEncodingWithAllowedCharacters方法。
stringByAddingPercentEncodingWithAllowedCharacters需要传一个 NSCharacterSet 对象。
如:将 stringByAddingPercentEscapesUsingEncoding 的写法
NSString * photoPath = @"http://101.200.198.172:8963/OurIMServer/00/gravatar/所有用户.png";
NSString *str = [photoPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
替换成 stringByAddingPercentEncodingWithAllowedCharacters 的写法 是:
NSString * photoPath = @"http://101.200.198.172:8963/OurIMServer/00/gravatar/所有用户.png";
NSString *str = [photoPath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];