Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In custom iOS keyboard detect the app

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

like image 321
Igor Barinov Avatar asked May 23 '15 01:05

Igor Barinov


2 Answers

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.

like image 182
Sunil Targe Avatar answered Sep 21 '22 10:09

Sunil Targe


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.

like image 29
Schemetrical Avatar answered Sep 18 '22 10:09

Schemetrical