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 里:

注意要把 “Provide build settings from” 这个选成你的 target, 如果是默认的 none,则不会带有项目的环境参数。这样脚本就没办法找到 app 的路径了:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# Type a script or drag a script file from your workspace to insert its path. # Configuration DESTINATION="/Library/Input Methods" APP_NAME="${FULL_PRODUCT_NAME}" SOURCE_APP="${BUILT_PRODUCTS_DIR}/${APP_NAME}" DEST_APP="${DESTINATION}/${APP_NAME}" PROCESS_NAME="${EXECUTABLE_NAME}" # 1. Kill the running process to release the file lock # (Ignores errors if process isn't running) pkill -f "$PROCESS_NAME" || true # 2. Ensure destination exists if [ ! -d "$DESTINATION" ]; then mkdir -p "$DESTINATION" fi # 3. Use rsync instead of cp # -a: Archive mode (preserves symlinks, permissions, times) # --delete: remove old files in destination that aren't in source rsync -a --delete "$SOURCE_APP/" "$DEST_APP/" # 4. Critical: Remove "Quarantine" attributes # macOS often marks copied apps as "damaged" or "unsafe" xattr -cr "$DEST_APP" # 5. Tell the system the app has been updated touch "$DEST_APP" |
Then, 就是搞定 debug attach 的问题了。

同样继续修改 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