如何在macOS中为纯C应用关联文件类型?
macOS纯C应用关联CSV文件打开的问题
我正在开发一款纯C应用,希望在macOS中通过点击CSV文件直接用该应用打开。
已完成操作
- 编写了纯C应用,可通过
*argv[]参数接收CSV文件路径并在main函数中处理 - 将编译后的可执行文件放入
myapp.app/Contents/MacOS目录 - 在
myapp.app/Contents下创建Info.plist文件,指定支持CSV文件类型
目前已可将该应用设为CSV文件的默认打开程序,但点击文件时无法打开,提示:
无法打开文档<document_name>。<app_name>无法打开“comma-separated value”格式的文件。
核心疑问
需要实现application(_:openFiles:)函数,但找到的示例均为Objective-C代码,而我使用的是纯C应用。
是否有方法为macOS纯C应用关联文档类型,或通过其他方式将打开的文件路径映射到.app应用的argv参数中?
我的Info.plist文件内容
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>csv</string> </array> <key>LSIsAppleDefaultForType</key> <string>Yes</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleTypeName</key> <string>comma-separated value</string> </dict> </array> </dict> </plist>
内容的提问来源于stack exchange,提问作者Daveman
相关产品推荐
相关产品推荐

