jeudi 21 juillet 2016

How to detect correctly language user of device objective-c?

I have a query about iOS. I want to detect language of my device, for change any texts in my app if language is english and other if isn't english. But when I detect language, always detect region and not detect language. In others words if I go to change language, this don't change. If I change region, language changes.

My code is:

 NSString *userLocale = [[NSLocale currentLocale] localeIdentifier];
NSString *userLanguage = [userLocale substringToIndex:2];
NSLog(@"%@", userLanguage); // return format "en", "es"... (english or spanish)

Could be that this problem appear because with [NSLocale currentLocale] get en_Us and this parameters depends of region?

Thanks!

Aucun commentaire:

Enregistrer un commentaire