Search code examples
iphoneiosipaduitextfield

How to check that the entered text is in arabic from arabic keyboard in UITextField programmatically?


How can we check that the selected keyboard is not English and it is in Arabic. So on later stage i convert the Arabic digits to English numeric digits for better search on web server.


Solution

  • You can know the current language of the phone. By the following code

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
        NSString *currentLanguage = [languages objectAtIndex:0];
    
        NSLog(@"Current Locale: %@", [[NSLocale currentLocale] localeIdentifier]);
        NSLog(@"Current language: %@", currentLanguage);
    

    If it is in Arabic, that means the keyboard will also comes in Arabic and user will enter the Arabic text.