13
14

More than 5 years have passed since last update.

iOS 9で言語設定の取得が変わった

Posted at

システムのカレント言語設定を調べるのに以下のようにしていました。

NSArray *languages = [NSLocale preferredLanguages];
NSString *lang = [languages objectAtIndex:0];
if ( [lang isEqualToString:@"ja"] ) {
    // 日本語
}

これまでは lang に @"ja"が入っていたのですが、iOS 9環境では、lang に @"ja-JP" が入ってきて、比較が通らなくなってしまいました。

下位互換もあるので、先頭2文字だけを切り出すことにしました。

NSString *lang = [[languages objectAtIndex:0] substringToIndex:2];
13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14