iOS9から[NSLocale preferredLanguages] の出力が変更された

以前ツイートした内容を自分で忘れていて検索する羽目になったのでブログにも書いておく。

iOS9から、[NSLocale preferredLanguages] の出力が ja から ja-JP に変更されたらしい。

Technical Note TN2418: Language Identifiers in iOS 9 に説明があった。

If you need to load resources manually, such as from a custom or server-side source, note that you should still rely on NSBundle for language matching to get consistent results.

とあるので、iOS9からはNSBundle を使うべきらしい。

今まで [NSLocale preferredLanguages] を使っていたところを、例えば下記のようにすれば良いはず。

    NSArray *languages = [[NSBundle mainBundle]preferredLocalizations];
    NSString *currentLanguage = [languages objectAtIndex:0];

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.