将文件类型与 swift 中的 iOS 应用程序相关联
associate file types with iOS application in swift
我是 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
}
这个问题我之前在. It was a possible duplicate of this QUESTION问过。但是,我没有得到解决方案,也找不到问题所在。
我的代码中缺少什么?感谢任何帮助
试试这个。我将你的代码复制并粘贴到我的 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>
我是 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
}
这个问题我之前在
我的代码中缺少什么?感谢任何帮助
试试这个。我将你的代码复制并粘贴到我的 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>