swift - PDF 未显示 Swift 共享扩展
问题描述
使用Swift5.3.2、iOS13.0、
我的共享扩展适用于图像和视频。
但是它不适用于 PDF。
问题是我的应用程序在我试图与我的应用程序共享的 PDF 文档的共享应用程序列表中不可见。
我知道必须在 info.plist 中正确设置规则。
我尝试了以下两次尝试 - 但都没有成功!
谁能告诉我 iOS 中的 PDF 共享扩展需要什么?
尝试1:Info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>100</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>25</integer>
</dict>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<key>NSExtensionPrincipalClass</key>
<string>CustomShareNavigationController</string>
</dict>
尝试2:Info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</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.file-url"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
).@count == $extensionItem.attachments.@count
).@count == 1
</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<key>NSExtensionPrincipalClass</key>
<string>CustomShareNavigationController</string>
</dict>
解决方案
当您在 Safari 中启动 PDF 共享时,它实际上会考虑 2 个输入项:PDF 和 URL。由于您的NSExtensionActivationRule
谓词明确指出@count == 1
,它将返回 false,因为有超过 1 个元素与您的谓词匹配。因此,解决方法是更改@count == 1
为@count >= 1
最适合您的应用程序的逻辑。
更新了对我有用的查询:
<key>NSExtensionActivationRule</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.file-url"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.jpeg"
|| ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.png"
).@count == $extensionItem.attachments.@count
).@count >= 1
</string>
推荐阅读
- asp.net - 如何使用 ViewBag 显示数据
- javascript - 如何根据javascript中的值从数组中删除对象
- laravel - 如何使用 Laravel 刀片渲染视图?
- java - 对具有相同属性名称的不同数据类型使用 ModelMapper
- python - 从日期时间差中提取小时与舍入 1 - Pandas DataFrame
- ios - 来自外部 url 的 Ionic 5 电容器/角度预览文件
- python - 错误:django.urls.exceptions.NoReverseMatch:找不到“登录”的反向。“登录”不是有效的视图函数或模式名称
- javascript - 警告:收到布尔属性“隐藏”的字符串“真”
- java - 如何对两个实体类和两个表(元数据和实际内容)进行建模以存储文件
- mysql - SQL SLECT 两个子查询,多行,没有任何条件