iOS URLEcode

作者: littleGG 发布时间: 2017-06-14 浏览: 1083 次 编辑

在进行webview链接跳转的时候会遇到链接中含有中文字符,这个时候我们需要编码中文字符,

- (NSString *)encodeChineseWordForURL {

NSCharacterSet *URLParamCharacterSet;

NSMutableCharacterSet *characterSet = [NSMutableCharacterSet new];

[characterSet formUnionWithCharacterSet:[NSCharacterSet URLQueryAllowedCharacterSet]];

[characterSet addCharactersInString:@"!*'();:@&=+$,/?#[]<>\"{}|\\`^% "];

URLParamCharacterSet = [characterSet copy];

return [self stringByAddingPercentEncodingWithAllowedCharacters:URLParamCharacterSet];

}

标签: