【问题标题】:associate file types with iOS application in swift快速将文件类型与 iOS 应用程序关联
【发布时间】:2015-08-19 04:00:52
【问题描述】:

我是 iOS 开发新手。我设计了一个自定义附件以通过邮件发送。当我收到邮件中的附件时,我想在我的应用程序中打开附件。 这是我的 info.plist

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>pvt file</string>
        <key>UTTypeIdentifier</key>
        <string>com.pryvateBeta.crypt.pvt</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>pvt</string>
        </dict>
    </dict>
</array>
<key>CFBundleDocumentsType</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>pvt file</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.pryvateBeta.crypt.pvt</string>
        </array>
    </dict>
</array>

这是我的 Appdelegate

func application(application: UIApplication, openURL Url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    let encrypteddata = NSData(contentsOfURL: Url)
    

    return true
}

我之前在LINK 中问过这个问题。这可能是这个QUESTION 的副本。但是,我没有得到解决方案,也找不到问题所在。

我的代码中缺少什么?任何帮助表示赞赏

【问题讨论】:

  • 使用应用程序目标编辑器的信息选项卡设置您的文档类型和导出的 UTI。它将正确设置 Info.plist。
  • plist 中是否缺少任何内容?这样我就可以按照你提到的方式添加它@matt

标签: ios swift email-attachments uti


【解决方案1】:

试试这个。我将您的代码复制并粘贴到我的 plist 中,但它不起作用。然后我创建了另一个 plist,它的代码如下。及其工作

       <key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.pryvateBeta.crypt.pvt</string>
        </array>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>CFBundleTypeName</key>
        <string>pvt file</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
    </dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeIdentifier</key>
        <string>com.pryvateBeta.crypt.pvt</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.mime-type</key>
            <string>application/pry</string>
            <key>public.filename-extension</key>
            <string>pvt</string>
        </dict>
    </dict>
</array>

【讨论】:

  • 不幸的是,还没有变化@Shebin
  • 真正包含什么?应该是Bundle ID + 文件扩展名?
  • 真的很管用。我还想知道一件事。我该如何处理这个文件?
  • 我想在我的一个 veiwcontrollers 中打开它。
  • 正如您在问题中提到的那样。该委托将调用.. 参数 url 包含您的文件(路径)
猜你喜欢
  • 2022-01-11
  • 2011-12-10
  • 1970-01-01
  • 2014-05-03
  • 2012-01-29
  • 2011-02-15
  • 2018-02-25
相关资源
最近更新 更多