iphone - 基于 plist 创建我自己的文件扩展名

标签 iphone cocoa cocoa-touch file-extension

我的应用程序处理 *.mndl 类型的文件,该文件只不过是自定义的 *.plist。 到目前为止,我一直在使用 *.plist 文件,但现在我想关联扩展名并能够从我意识到的任何其他应用程序打开 *.mndl 文件将 file.plist 重命名为 file.mndl 不起作用。 (因此,我什至不知道我是否正确执行了扩展关联和导出操作)

我从计算机向自己发送了一个文件 file.mndl ,当在 mail.app 中收到时,我得到了 file.mndl.plist(它被自动重命名,这是在重置我的 iPad 时发生的)

如何创建自己的 mndl 文件,同时能够使用 NSDictionary 类中的 +dictionaryWithContentsOfFile: 读取其内容?

即使我正在使用 iOS,我也相信这种东西是从 MacOS 和 Cocoa 移植的。所以 Cocoa 开发者也可以知道这一点。

感谢您的评论/回答。

谢谢

回答: 只是为了完成目的这是我对 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>

最佳答案

至少对于 Cocoa(桌面)应用程序,您需要将以下信息添加到应用程序的 Info.plist 中。

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

显然,您应该将统一类型标识符更改为适当的内容。 (我通常会做 com.markdouma.something,因为那是我的网站)。

请注意,如果您计划通过创建 NSDocument 子类来处理加载文件来使用 Cocoa 的 NSDocument 架构,则只需为 NSDocumentClass 指定一个条目。否则,您始终可以实现以下 < NSApplicationDelegate > (将其视为应用程序委托(delegate)协议(protocol))方法:

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

这将为您提供一个 NSString 的 NSArray,表示用户在 Finder 中双击(或拖动到应用程序图标等)的文件的 POSIX 路径

如果你想走NSDocument路线,可以重写NSDocument的以下方法

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

并使用 [[NSDictionarydictionaryWithContentsOfFile:[url path]]retain] 创建字典;

希望这有帮助...

关于iphone - 基于 plist 创建我自己的文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3827558/

相关文章:

Ios Swift 添加带有过渡/效果的 UIImageView

iPhone - 只允许在一个 View Controller 上横向定位

cocoa-touch - 没有即时搜索的 UISearchDisplayController : How do I control the dimming of the TableView?

iPhone 应用程序设计 Storyboard与 nib

cocoa-touch - CMutablePointer<NSRange> 死胡同

ios - 我可以在后台观察来电和去电吗?

swift - nswindow 动画师无法在窗口 Controller 中工作

objective-c - Cocoa 的图形库

cocoa - 删除时如何手动管理核心数据关系

ios - XCode - 启用推送通知需要已添加的 Apple ID