简体   繁体   中英

In custom iOS keyboard detect the app

How to detect in which app my custom keyboard used and show different button? Eg in Twitter I would add @ to string I post into input field and in Reddit /r/

It is possible through following code. As you'll get bundle identifier of the app where you're using your custom keyboard.

Swift

    let hostBundleID = self.parentViewController!.valueForKey("_hostBundleID")
    let currentHostBundleID = String(hostBundleID)
    print(currentHostBundleID);

From bundle identifier you can find app name easily.

This is not possible. An extension runs sandboxed and is only fed information from the API and cannot access anything else. The keyboard can only receive text context changes and activate/deactivate calls. Being able to detect an app lies outside of the extension sandbox and therefore is impossible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM