在ios下需要实现一个ftp的客户端,发现中文的目录和文件名是乱码,google了很久,apple自己带的ftp示例里面有方法解决:
- (NSDictionary *)entryByReencodingNameInEntry:(NSDictionary *)entry encoding:(NSStringEncoding)newEncoding
// CFFTPCreateParsedResourceListing always interprets the file name as MacRoman,
// which is clearly bogus <rdar://problem/7420589>. This code attempts to fix
// that by converting the Unicode name back to MacRoman (to get the original bytes;
// this works because there's a lossless round trip between MacRoman and Unicode)
// and then reconverting those bytes to Unicode using the encoding provided.
{
NSDictionary * result;
NSString * name;
NSData * nameData;
NSString * newName;
newName = nil;
// Try to get the name, convert it back to MacRoman, and then reconvert it
// with the preferred encoding.
name = [entry objectForKey:(id) kCFFTPResourceName];