1

我正在开发一个应用程序扩展程序,我希望允许用户与主机应用程序共享各种文件。

示例:选择照片,选择通过应用共享,照片保存到共享文件夹,然后在用户下次打开主机应用时可用。

我已经准备好从共享文件夹中读取主机应用程序,并且现在只使用图像设置扩展名,但我坚持的一点是检索文件数据(我不确定的 blob 或路径?)然后将其写入共享文件夹。

这是扩展程序的相关部分:

 override func didSelectPost() {
    let content = extensionContext!.inputItems[0] as NSExtensionItem
    for attachment in content.attachments as [NSItemProvider] {

        // Image attachment
        if attachment.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
            // save this to file in shared folder for host app to retrieve...
        }

    }

    self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
}

我查看了许多其他问题,但似乎找不到适合我用例的任何内容。

4

1 回答 1

0

据我了解,我只是尝试回答您的问题:

请检查 Plist 文件,如下图所示:

在此处输入图像描述

如果它与我建议的不同,那就去做吧......

我希望,您是否从选择项目->功能中添加了“应用程序组” ...


如果上面提到的 plist 不起作用,则按以下方式检查 SUBQUERY:

<key>NSExtenstionActivationRule</key>
<string>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.plain-text"
            || 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"
            )
            ).@count == $extensionItem.attachments.@count
            ).@count == 1
</string>

如果那么也不起作用,那么请通过

developer.apple.com 的应用程序扩展

我想,这会有所帮助...

于 2015-10-28T10:39:54.127 回答