views:

112

answers:

2

I've got an app, written in Obj-C. The info.plist has a list of file types that the app can open. I'm pretty sure that this is working because when I try to drag a file of an unacceptable type, the app doesn't highlight, but when I drag a file of an acceptable type, it does highlight, and lets me drop.

When I drop, the app starts up, correctly, however, then I get a dialog saying:

The document "foo.tiff" could not be opened. DocView cannot open files in the "TIFF File" format.

I DO have this in my info.plist

<key>CFBundleTypeExtensions</key>
<array>
   <string>tif</string>
   <string>tiff</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>TIFFFile.icns</string>
<key>CFBundleTypeName</key>
<string>TIFF File</string>
<key>CFBundleTypeOSTypes</key>
<array>
   <string>TIFF</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Documents/</string>

Thanks.

+1  A: 

Does your app actually handle the file opening?

If it's an NSDocument application, you need to implement one of the file reading methods such as readFromData:ofType:error:. In an ordinary NSApplication your app delegate should handle it in application:openFile:. In both cases you need to return YES to acknowledge that you've successfully opened the file.

If you have implemented this, is the message being sent?

walkytalky
I have a Document class which is subclassed off of NSDocument. I have both readFromData:ofType:errors: and readFromURL:ofType:errors. Neither seems to be called.
Brian Postow
Fair enough. JWWalker has probably nailed it, anyway.
walkytalky
yeah, he application:openFile is the way I needed to go. Thanks!
Brian Postow
+1  A: 

First, the part of the Info.plist that you show is within the CFBundleDocumentTypes array, not at the top level of the Info.plist, right?

Second, under LSHandlerRank you have Documents/, which is not a legal value, nor is Documents.

Third, you probably need to add NSDocumentClass.

JWWalker
Where do I need to add NSDocumentClass? I have a Document class which is subclassed off of NSDocument already...
Brian Postow
It's another key in the dictionary that includes the entries you posted:`<key>NSDocumentClass</key> <string>YourDocumentClassName</string>`
walkytalky
Is that the super class? I have 4 document classes subclassed off of Document...
Brian Postow
@Brian So which one do you want to get instantiated and sent the `read...` message to open a TIFF file?
walkytalky
@walkytalky The problem is that I don't actually KNOW until I've actually opened the file... I have three kinds of .tiff files, multipage tiffs, single page images, and documents that are in multiple files, one per page (img-001 img-002 img-003, etc) and I don't know that until I've opened the file...
Brian Postow
@Brian: In that case I guess you don't want to specify NSDocumentClass. Receive the file in an app delegate method like `application:openFile:` and then figure out what kind of document to use.
JWWalker

related questions