NSString *hanziText = @"今天天气不错";
if ([hanziText length]) {
NSMutableString *ms = [[NSMutableString alloc] initWithString:hanziText];
if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandarinLatin, NO)) {
//带音调
NSLog(@"pinyin: %@", ms);
}
if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformStripDiacritics, NO)) {
//去除音调
NSLog(@"pinyin: %@", ms);
}
}