现在我正在开发应用程序,该应用程序应实现共享扩展以从邮件应用程序共享附件。它应该支持不同的文件扩展名(几乎所有类型的文档)。从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