代码之家  ›  专栏  ›  技术社区  ›  Brian Postow

创建可以打开给定格式文件的应用程序

  •  2
  • Brian Postow  · 技术社区  · 14 年前

    我有一个用obj-c编写的应用程序。info.plist有一个应用程序可以打开的文件类型列表。我非常肯定这是可行的,因为当我试图拖动一个不可接受的文件时,应用程序不会突出显示,但当我拖动一个可接受的文件时,它会突出显示,并让我放下。

    但是,当我退出时,应用程序会正确启动,然后我会得到一个对话框,上面说:

    无法打开文档“foo.tiff”。DocView无法以“TIFF文件”格式打开文件。

    我的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>
    

    谢谢。

    2 回复  |  直到 14 年前
        1
  •  4
  •   walkytalky    14 年前

    你的应用程序真的能处理文件的打开吗?

    如果是 NSDocument 应用程序,您需要实现一种文件读取方法,例如 readFromData:ofType:error: . 在一个普通的应用程序中,你的应用程序代理应该在 application:openFile: . 在这两种情况下,您都需要返回 YES 确认已成功打开文件。

    如果您已经实现了这一点,那么消息是否正在发送?

        2
  •  1
  •   JWWalker    14 年前

    首先,您显示的info.plist部分在cfbundleddocumenttypes数组中,而不是在info.plist的顶层,对吗?

    其次,在lshandlerrank下,您有documents/,这不是合法值,也不是documents。

    第三,您可能需要添加nsdocumentclass。