現在我正在開發應用程序,該應用程序應實現共享擴展以從郵件應用程序共享附件。它應該支持不同的文件擴展名(幾乎所有類型的文檔)。從Apple文檔中,我瞭解到我必須在Info.plist中使用Predicate,但在所有的答案中,我發現我必須在代碼中使用它。現在我陷入了困境,無法繼續前進。這是我想從此post使用的謂詞。從郵件應用程序分享附件在iOS中的分享擴展
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
(
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.pdf"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg-2000"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.tiff"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.compuserve.gif"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.bmp"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.word.doc"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.openxmlformats.wordprocessingml.document"
)
)[email protected] == [email protected]
)[email protected] == 1
誰能告訴我如何在我的SWIFT代碼中使用此斷言:
for attachment in content.attachments as! [NSItemProvider] {
if attachment.hasItemConformingToTypeIdentifier(contentType) {
attachment.loadItemForTypeIdentifier(contentType, options: nil) { data, error in
if error == nil {
let url = data as! NSURL
if let fileData = NSData(contentsOfURL: url) {
self.selectedFile = NSData(data: fileData)
}
} else {
let alert = UIAlertController(title: "Error", message: "Error loading file", preferredStyle: .Alert)
let action = UIAlertAction(title: "Error", style: .Cancel) { _ in
self.dismissViewControllerAnimated(true, completion: nil)
}
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
}
這裏是我的NSExtensionActivationRule:
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsAttachmentsWithMaxCount</key>
<integer>1</integer>
</dict>
在此先感謝。
generateImageName()你能解釋一下這個函數做什麼嗎? –
這是我的功能,它只是從拾取的文件的路徑中獲取原始文件名。 – Artiom