iOS:如何让用户在 SwiftUI 应用程序中共享来自 Safari/Chrome 的 URL

Her*_*. F 5 ios swiftui ios15

我想在我的应用程序中添加一项功能,浏览网页的用户可以按链接上的“共享”,当正常的应用程序出现时,如“消息”、“邮件”、“Instagram”等,他们可以看到我的应用程序,当他们点击它时,我想处理我的应用程序内的网址。

我尝试过搜索:“swiftui 添加从 safari 到应用程序的链接”,但我只能找到处理 deepLinks 的方法onOpenURL

我假设根据我分享这些应用程序之一的链接时获得的经验,我必须为 SwiftUI 应用程序构建一个扩展?

我想知道是否有任何解决方案,或者我是否使用错误的术语来搜索这个问题。

任何帮助将不胜感激,谢谢!

use*_*239 0

您想要的是让您的应用程序出现在UIActivityViewController

在此输入图像描述

添加流动到info.plist

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key> 
        <dict>
            <key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
            <integer>1</integer> 
            <key>NSExtensionActivationSupportsText</key>
            <true/>
            <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
            <integer>1</integer>
        </dict>
        <key>NSExtensionJavaScriptPreprocessingFile</key>
        <string>testshare</string>
    </dict> 
    <key>NSExtensionMainStoryboard</key>
    <string>MainInterface</string>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.share-services</string>
</dict> 
Run Code Online (Sandbox Code Playgroud)

还要检查这个答案