简体   繁体   English

如何通过将文件拖放到非基于文档的Cocoa应用程序来启动它?

[英]How do I launch a non-document-based Cocoa application by dropping files on it?

The only way I've been able to get this working is with a document-based application (which this app isn't). 我能够使它正常工作的唯一方法是使用基于文档的应用程序(该应用程序不是)。 In my non-document-based application I've defined the supported Document Types (from the Properties tab of the Target info window) and my AppDelegate implements application:openFile: and application:openFiles: . 在非基于文档的应用程序中,我已经定义了受支持的文档类型(从“目标信息”窗口的“属性”选项卡中),并且我的AppDelegate实现了application:openFile:application:openFiles: That enables dropping files on the application's Dock icon when it has already been launched but not its icon in the Finder (launched or otherwise). 这样就可以在启动应用程序时将其拖放到应用程序的Dock图标上,而不是将其拖放到Finder中的图标上(已启动或以其他方式)。 What am I missing? 我想念什么?

Updated 更新

As requested, my Document Types array: 根据要求,我的文档类型数组:

<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>nsf</string>
            <string>nsfe</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>NSF Soundtrack</string>
        <key>CFBundleTypeRole</key>
        <string>None</string>
        <key>LSTypeIsPackage</key>
        <false/>
        <key>NSPersistentStoreTypeKey</key>
        <string>InMemory</string>
    </dict>
</array>

Two parts of this make me suspicious: 这两个部分使我感到怀疑:

    <key>CFBundleTypeRole</key>
    <string>None</string>

Don't you mean this to be Viewer at least? 您不是说这至少要成为Viewer吗?

    <key>NSPersistentStoreTypeKey</key>
    <string>InMemory</string>

What are you trying to do here? 您想在这里做什么? Why would your on-disk file be specified as an in-memory Core Data persistent store? 为什么将磁盘上的文件指定为内存中的Core Data持久存储? If you want to just hoist the whole thing into memory when you load it, that's called Binary or XML, not InMemory. 如果要在加载时将整个内容提升到内存中,则称为Binary或XML,而不是InMemory。

I also recommend that you define UTIs for your document types, not just extensions. 我还建议您为文档类型定义UTI,而不仅仅是扩展名。

You should also double-check what Launch Services thinks is going on by using lsregister . 您还应该使用lsregister仔细检查Launch Services认为正在进行的lsregister Sometimes the problem is that you have multiple versions of your app lying around and Launch Services hasn't found the one you think it should have. 有时,问题在于您的应用有多个版本,而Launch Services找不到您认为应该拥有的版本。 You can look the Launch Services database like this: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump 您可以这样查找Launch Services数据库:/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump

This should work on 10.5 and 10.6. 这应该适用于10.5和10.6。 10.4 has lsregister in a different place. 10.4将lsregister放在其他位置。 I usually use locate to find it rather than trying to memorize it. 我通常使用locate来查找它,而不是尝试记住它。

在“目标”设置中,转到“属性”选项卡,然后添加到“文档类型”表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM