8

当单击 iOS Safari 中的“共享”按钮(从工具栏或长按链接)时,我希望我的应用程序显示为“在...中打开”选项(例如“在新闻中打开"),这样我的应用程序(另一种类型的网络浏览器)就可以打开Safari 共享的任何内容http://或URL。https://

我已经在我的文件中注册了文档类型“URL”(我认为它是正确的类型——如果这个假设是错误的,请纠正我!)我可以从 Apple 的“注册应用程序支持的文件类型”文档info.plist中猜到。 ,他们的技术问答,以及这些相关的 StackOverflow 帖子1 2 3CFBundleDocumentTypes

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>appIcon320</string>
            <string>appIcon64</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>URL</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>   <!-- Note: I have also tried 'Viewer' -->
        <key>LSHandlerRank</key>
        <string>Owner</string>    <!-- Note: I have also tried 'Default' -->
        <key>LSItemContentTypes</key>
        <array>
            <string>public.url</string>
        </array>
    </dict>
</array>

我还写了这个存根方法AppDelegate.swift(尽管我认为它实际上与让我的应用程序显示为“在...中打开”选项的第一阶段的成功无关):

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {opening-in-app-getting-uiapplicationlaunchoptionsurlkey-from-launchoptions?rq=1
    print("Received URL: \(url); from source: \(options[.sourceApplication] ?? "nil"); with annotation: \(options[.annotation] ?? "nil")")
    return true
}

...但是,我的应用程序仍未显示为“在...中打开”选项。我必须补充一点,应用程序图标与应用程序正确绑定,并且info.plist文件在 Xcode 中打开正常,所以我可以确认它没有损坏。

所以我有三个问题:

  1. 长按链接并点击“共享...”按钮后,Safari 共享的文档类型确实是“URL”吗?

  2. 按下 Safari 工具栏中的图形按钮后,看起来像(混淆地也称为“共享”按钮),Safari 共享的文档类型是否像以前一样,“URL”?

  3. CFBundleDocumentTypes是否为 URL 类型的文档编写了正确的文档?或者如果 Safari 共享其他内容,它是什么(以及我应该如何编写它)?

4

0 回答 0