macOS third-party input method debugging method

macOS 已经更新到 26 It's, 但对于第三方输入法的支持一直没有任何变化最新的 Xcode 26 破坏了之前我一直用的方法——直接把编译路径改到 /Library/Input Method 现在这么做 xcode 会报错因为项目依赖的 framework 不会再写到这个目录了

只有去掉所有更改编译目录的设置后编译就可以成功我猜测大概是因为新版的 SPM 不再遵循 Xcode 项目输出目录设置了……总之已经用了好几年的办法不行了得换新的

新的 debug 方案

很多人说macOS 第三方输入法是不能直接 attach 的这样会导致系统卡死其实不会自从上次苹果更新了 macOS 第三方输入法架构后就没问题了只是不要在 attach 的情况下切换到 Xcode 就行所以恢复到传统的编译→复制app到 /Library/Input Method →注销系统→在系统终端里查看 print 这种流程是万万无法接受的

根据 Gemini 3 的建议首先我一直用的办法确实是不行了回复到默认编译路径后可以用 post script 杀掉当前进程并将编译的 app 移动到输入法目录这就解决了app位置问题

It is noteworthy that,不能使用 Xcode 的 run script因为那是编译的一部分不论如何设置顺序Xcode 都会在链接和签名之前执行这样你拷贝过去的 app 就是未完成的状态就不能运行的

解决办法是编辑项目的 scheme添加脚本到 build 的 post-actions 里

使用 post-actions 来将编译好的 app 移动到 /Library/Input Method 目录
使用 post-actions 来将编译好的 app 移动到 /Library/Input Method 目录

注意要把 “Provide build settings from” 这个选成你的 target如果是默认的 none则不会带有项目的环境参数这样脚本就没办法找到 app 的路径了

Then, 就是搞定 debug attach 的问题了

使用 /Library/Input Method 目录代替原本 app 路径进行debug
使用 /Library/Input Method 目录代替原本 app 路径进行debug

同样继续修改 scheme这次是 run 页面在可执行文件这里要选 other然后手动定位到 /Library/Input Method 目录下的 app 上这样在编译后 xcode 就会自动从那里启动进程代替系统启动所有 print 等debug 信息就还能正常显示在终端

我曾尝试关闭 Xcode 自动执行让它等待我手动启动但这样的结果就是系统启动了输入法由于启动身份不同在 xcode 上 debug 出来的信息全都被 <private> 遮盖了

Original article written by LogStudio:R0uter's Blog » macOS third-party input method debugging method

Reproduced Please keep the source and description link:https://www.logcg.com/archives/4196.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。