Share-Anhang von der Mail-App mit Freigabeerweiterung in iOS

Jetzt arbeite ich an der App, die die Freigabeerweiterung implementieren soll, um Anhänge aus der Mail-App freizugeben. Es sollte verschiedene Dateierweiterungen unterstützen (fast alle Arten von Dokumenten). Aus Apple-Dokumenten habe ich verstanden, dass ich Predicate in meiner Info.plist verwenden muss, aber in Antworten auf SO habe ich festgestellt, dass ich es in Code verwenden muss. Jetzt bin ich dran und kann nicht weiter machen. Hier ist das Prädikat, das ich aus diesem @ verwenden möchPos.

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"
            )
).@count == $extensionItem.attachments.@count
).@count == 1

Kann mir jemand raten, wie man dieses Prädikat in meinem Swift-Code verwendet:

    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)
                }
            }
        }
    }

Hier ist meine NSExtensionActivationRule:

        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsAttachmentsWithMaxCount</key>
            <integer>1</integer>
        </dict>

Danke im Voraus

Antworten auf die Frage(2)

Ihre Antwort auf die Frage