Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

iphone - Creating my own file extension based on plist

My application handles with files of type *.mndl which is not more than a customized *.plist. Up until now I've been using *.plist files but now I want to associate the extension and be able to open *.mndl files from any other app I have realized that renaming file.plist to file.mndl does not work. (Hence, I don't even know if I did correctly the extension association and exportation thing)

I sent to myself a file file.mndl from the computer and when received in mail.app I got file.mndl.plist (It was automatically renamed, this happened when reseting my iPad)

How can I create my own mndl files while being able to read its content using +dictionaryWithContentsOfFile: from NSDictionary class?

Even I am working with iOS I believe this kind of things were ported from MacOS and Cocoa. So Cocoa developers also could know this.

Your comments/answers are appreciated.

Thanks

ANSWERED: Just for completion purposes This is the addition I made to my info.plist:

    <key>UTExportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.data</string>
            </array>
            <key>UTTypeDescription</key>
            <string>Mandala Chart File</string>
            <key>UTTypeIdentifier</key>
            <string>com.nacho4d.Accordion.mndl</string>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.filename-extension</key>
                <string>mndl</string>
            </dict>
        </dict>
    </array>
    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>Document320Icon.png</string>
                <string>Document64Icon.png</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>Mandala Chart File</string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>LSHandlerRank</key>
            <string>Owner</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.nacho4d.Accordion.mndl</string>
            </array>
        </dict>
    </array>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

At least for a Cocoa (desktop) app, you'd want to add the following information to your application's Info.plist.

http://www.markdouma.com/developer/nacho.plist

Obviously, you should change the uniform type identifier to something appropriate. (I usually do com.markdouma.something, since that's my website).

Note that you only want to specify an entry for NSDocumentClass if you plan on using Cocoa's NSDocument architecture by creating an NSDocument subclass to handle loading the files. Otherwise, you could always just implement the following < NSApplicationDelegate > (read that as application delegate protocol) method:

- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames;

That will give you an NSArray of NSStrings representing the POSIX paths to the files the user double-clicked on in the Finder (or dragged to the app icon, etc.)

If you want to go the NSDocument route, you can override the following method of NSDocument

- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)type error:(NSError **)outError;

and create your dictionary with [[NSDictionary dictionaryWithContentsOfFile:[url path]] retain];

Hope this helps...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...