简体   繁体   中英

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: . 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). 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?

    <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? If you want to just hoist the whole thing into memory when you load it, that's called Binary or XML, not InMemory.

I also recommend that you define UTIs for your document types, not just extensions.

You should also double-check what Launch Services thinks is going on by using 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. You can look the Launch Services database like this: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump

This should work on 10.5 and 10.6. 10.4 has lsregister in a different place. I usually use locate to find it rather than trying to memorize it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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