Swift 创建一个MacOS输入法
参考资料: [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键,即可出现资源库选项)里,然后就可以在系统输入法里添加了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |