【问题标题】:Share extension does not appear in capable apps if NSExtensionActivationRule is set for audio only如果 NSExtensionActivationRule 设置为仅用于音频,则共享扩展不会出现在支持的应用程序中
【发布时间】:2018-08-24 19:53:25
【问题描述】:

我正在尝试创建一个共享扩展程序,用户可以在其中从任何功能强大的应用上传她的录音。该文档甚至有一个简单的示例(参见Declaring Supported Data Types for a Share or Action Extension)(也在this SO answer 中提出),但它不适用于任何录音机(在iOS 10.3.3、iPad 上)。

看着Uniform Type Identifiers Reference,我需要public.audio。分享扩展Info.plist中的相关条目:

为了缩小范围,我尝试将NSExtensionActivationRule 更改为public.mpeg4public.audiovisual-content,结果相同。

当我将NSExtensionActivationRule 更改为符合public.image 时,它会显示在照片应用程序中:

SUBQUERY (
    extensionItems,
    $extensionItem,
    SUBQUERY (
        $extensionItem.attachments,
        $attachment,
        ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
    ).@count == $extensionItem.attachments.@count
).@count == 1

NSExtensionActivationRule 更改为TRUEPREDICATE 字符串将使其最终也出现在音频应用程序中,但当然,这不会在App Store 中被接受。

我还尝试了干净启动的上述每个步骤(即干净 + 干净构建文件夹 + 删除 DerivedData 内容 + 从 iPad 上删除应用程序),但结果相同。

This SO question 似乎也相关,但更改共享扩展的部署目标并没有帮助。

我错过了什么吗?

【问题讨论】:

  • 你找到什么了吗?

标签: ios share-extension


【解决方案1】:

注意:正如 Jamshed Alam 在他的评论中所说,iOS 13 的变化使这个答案过时了

我的共享扩展允许将音频文件上传到 Firebase 后端,我天真地假设录音应用会适当地声明其支持的文件类型,但事实并非如此。大多数符合多个统一类型标识符(请参阅reference),其中public.data 是最常见的。

我找到了this Github issue from 2014 并将其用作参考。它的标题完美地概括了这个问题:

共享扩展将在明确支持全部时显示 提供的活动项目

使用NSExtensionActivationDictionaryVersion 的解决方案也对我有用。根据Information Property Key List Reference

激活字典版本 1 仅当应用扩展处理 所有由宿主应用项目提供商提供的资产类型

激活字典版本 2 当应用扩展处理 at 至少一种主机应用项目提供商提供的资产类型

我的分享扩展的 Info.plist 现在看起来像这样:

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationDictionaryVersion</key>
            <integer>2</integer>
            <key>NSExtensionActivationSupportsAttachmentsWithMinCount</key>
            <integer>1</integer>
            <key>NSExtensionActivationSupportsFileWithMaxCount</key>
            <integer>20</integer>
        </dict>
    </dict>
    <key>NSExtensionMainStoryboard</key>
    <string>MainInterface</string>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.share-services</string>
</dict>

或者在 Xcode 中:

除了NSExtensionActivationDictionaryVersion 之外,只使用NSExtensionActivationSupportsFileWithMaxCount 可能就足够了。

【讨论】:

  • 你测试过 iOS 13 吗?不再工作共享扩展,苹果完全删除了共享扩展的 openURL:..() 方法。
  • 感谢您的更新!郑重声明,自去年春天以来就没有接触过 iOS 的东西......
  • 请测试并告诉我是否有任何解决方法。
【解决方案2】:

添加public.mpeg-4-audio 有助于在共享表中显示以前不会为public.audio 显示的应用程序。对每种扩展类型都这样做可能是不可行的。但扩展列表可以在Uniform Type IdentifiersAudiovisual content types下找到。

最好的情况似乎是这样构建查询。我已经包含了一些著名的扩展,但上面的链接中还有其他的。

SUBQUERY(
    $extensionItem.attachments, 
    $attachment, 
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.mpeg-4-audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.mp3" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.windows-media-wma" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.aifc-audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.aiff-audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.midi-audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.ac3-audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.microsoft.waveform-audio" ||
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.OTHER_EXTENSIONS" ||
).@count = 1

【讨论】:

    猜你喜欢
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 2020-08-05
    • 2015-04-06
    • 1970-01-01
    相关资源
    最近更新 更多