Swift 创建一个MacOS输入法

    xiaoxiao2021-03-26  24

    参考资料:

    [1] mac上使用qt,进行输入法的开发 http://blog.csdn.net/dinjay/article/details/7468268

    [2] Swift 使用 InputMethodKit 写输入法  https://www.logcg.com/archives/2078.html

    [3] InputMethodKit  https://developer.apple.com/reference/inputmethodkit

    [4] Mac 示例 http://developer.apple.com/library/mac/#samplecode/NumberInput_IMKit_Sample/Introduction/Intro.html

    [5] StackOverflow : http://stackoverflow.com/questions/27813151/how-to-develop-a-simple-input-method-for-mac-os-x-in-swift

    步骤:

    1.  在Xcode中,创建一个project,类型是 Cocoa Application,按照[2]的建议命名:

    在 Product Name 里填写:   YourAppName

    在 Orgnization Identifier 里填写:  com.YourName.inputmethode

    于是,你的APP的 Bundle Identifier 就是: com.YourName.inputmethod.YourAppName

    2. 注意去掉所有勾,确认,创建工程。

    3. 然后进入工程,删除有关界面的项目,包括窗口和MainMenu。

    4.  在plist里,添加一些项目,与[4] Mac 示例里的完全一致,其中有些值按照[2]的建议填写。这些项目是:

    Application is background only(自带项目)= YES  

    InputMethodConnectionName = YourConnectionName(详见示例代码,[2][5])

    InputMethodServerControllerClass = $(PRODUCT_MODULE_NAME).YourClassName(其中,YourClassName 是要添加的类名)

    tsInputMethodIconFileKey = YourIcon.tiff

    tsInputMethodCharacterRepertoireKey 类型为Array,其中新建项目 Item 0 = Latn

    5.  在工程里,新建类 YourClassName,按[2]的示例代码,编译。注意,[5]是正确的代码。

    6.  把编译好的App拷贝到系统的资源库/InputMethod(Finder,前往,按住Option键,即可出现资源库选项)里,然后就可以在系统输入法里添加了。

    转载请注明原文地址: https://ju.6miu.com/read-661280.html

    最新回复(0)