xcode 6.1 iOS 8.1 NSLocale displayNameForKey NSLocaleIdentifier return nil

后端 未结 5 2278
旧时难觅i
旧时难觅i 2021-02-12 20:52
- (NSString *)countryNameByCode:(NSString*)countryCode
{
    NSString *identifier = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: countryCode}];
    NSStrin         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-12 21:18

    This works for me

    NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:[NSLocale currentLocale].localeIdentifier];
    
     for (AVSpeechSynthesisVoice *voice in [AVSpeechSynthesisVoice speechVoices]) {
                NSString *languageLocalised = [currentLocale displayNameForKey:NSLocaleIdentifier value:voice.language];
                NSLog(@"%@ displayNameForKey %@: %@", currentLocale.localeIdentifier, voice.language, languageLocalised);
     }
    

提交回复
热议问题