开发者

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>L开发者_如何学CSTypeIsPackage</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.


In your Target settings, go to the Properties tab and add to the Document Types table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜