可以把汉字字符串转换成拼音,并且支持是否在拼音间插入空格

- (NSString *)chineseToPinyin:(NSString *)chinese withSpace:(BOOL)withSpace {
if (chinese) {
CFStringRef hanzi = (__bridge CFStringRef)chinese;
CFMutableStringRef string = CFStringCreateMutableCopy(NULL, 0, hanzi);
CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO);
CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO);
NSString *pinyin = (NSString *)CFBridgingRelease(string);
if (!withSpace) {
pinyin = [pinyin stringByReplacingOccurrencesOfString:@" " withString:@""];
}
return pinyin;
}
return nil;
}