How to check programmatically what international keyboards are installed on iPhone?

前端 未结 1 1768
轻奢々
轻奢々 2021-02-10 22:07

I\'m working on an app where the user can search a database with several languages. I want to know which keyboards are installed on his device, if he doesn\'t have a specific on

相关标签:
1条回答
  • 2021-02-10 22:25

    You can find it in NSUserDefaults:

    NSDictionary* defaults = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
    

    I tested it on iOS Simulator (iOS 5.0). I have only US keyboard installed. Contents of defaults:

    AppleITunesStoreItemKinds =     (
            eBook,
            document,
            "software-update",
            booklet,
            "itunes-u",
            newsstand,
            artist,
            podcast,
            "podcast-episode",
            software
        );
        AppleLanguages =     (
            en,
            fr,
            de,
            ja,
            nl,
            it,
            es,
            pt,
            "pt-PT",
            da,
            fi,
            nb,
            sv,
            ko,
            "zh-Hans",
            "zh-Hant",
            ru,
            pl,
            tr,
            uk,
            ar,
            hr,
            cs,
            el,
            he,
            ro,
            sk,
            th,
            id,
            ms,
            "en-GB",
            ca,
            hu,
            vi
        );
        AppleLocale = "en_US";
        NSInterfaceStyle = macintosh;
        NSLanguages =     (
            en,
            fr,
            de,
            ja,
            nl,
            it,
            es,
            pt,
            "pt-PT",
            da,
            fi,
            nb,
            sv,
            ko,
            "zh-Hans",
            "zh-Hant",
            ru,
            pl,
            tr,
            uk,
            ar,
            hr,
            cs,
            el,
            he,
            ro,
            sk,
            th,
            id,
            ms,
            "en-GB",
            ca,
            hu,
            vi
        );
    }
    

    Then I added russian keyboard and contents of NSUserDefaults become:

    {
        AppleITunesStoreItemKinds =     (
            eBook,
            document,
            "software-update",
            booklet,
            "itunes-u",
            newsstand,
            artist,
            podcast,
            "podcast-episode",
            software
        );
        AppleKeyboards =     (
            "en_US@hw=US;sw=QWERTY",
            "ru_RU@hw=Russian;sw=Russian"
        );
        AppleKeyboardsExpanded = 1;
        AppleLanguages =     (
            en,
            fr,
            de,
            ja,
            nl,
            it,
            es,
            pt,
            "pt-PT",
            da,
            fi,
            nb,
            sv,
            ko,
            "zh-Hans",
            "zh-Hant",
            ru,
            pl,
            tr,
            uk,
            ar,
            hr,
            cs,
            el,
            he,
            ro,
            sk,
            th,
            id,
            ms,
            "en-GB",
            ca,
            hu,
            vi
        );
        AppleLocale = "en_US";
        NSInterfaceStyle = macintosh;
        NSLanguages =     (
            en,
            fr,
            de,
            ja,
            nl,
            it,
            es,
            pt,
            "pt-PT",
            da,
            fi,
            nb,
            sv,
            ko,
            "zh-Hans",
            "zh-Hant",
            ru,
            pl,
            tr,
            uk,
            ar,
            hr,
            cs,
            el,
            he,
            ro,
            sk,
            th,
            id,
            ms,
            "en-GB",
            ca,
            hu,
            vi
        );
    }
    

    So, you need to use AppleKeyboards and AppleKeyboardsExpanded keys.

    0 讨论(0)
提交回复
热议问题