菜鸟教程小白 发表于 2022-12-11 19:43:11

ios - 如何使用 URLScheme 在 facebook 或 google 上分享帖子


                                            <p><p>我想在 facebook 上分享一个 HTML 链接,而无需安装 SDK,例如 WhatsApp 或 twitter。我正在使用以下代码在 facebook 上分享链接。但我想在没有打开 Safari 浏览器的情况下将帖子分享到 Direct 应用程序。
请告诉我这是否可能。我已经搜索了很多但没有找到任何解决方案。</p>

<pre><code>//For share twitter

let urlWhats = &#34;twitter://post?message=\(fileURL)&#34;
let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
let whatsappURL = URL(string: urlString!)
if UIApplication.shared.canOpenURL(whatsappURL!)
{
    UIApplication.shared.open(whatsappURL!, options: [:], completionHandler: nil)
}


//For Facebook
let shareURL = &#34;https://www.facebook.com/sharer/sharer.php?u=&#34; + url

if let url = URL(string:shareURL)
{
    let vc = SFSafariViewController(url: url, entersReaderIfAvailable: true)
    vc.delegate=self
    present(vc, animated: true)
}
</code></pre>

<p>提前致谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>要在 FB 中分享,请使用“FacebookShare”</p>

<pre><code>import FBSDKShareKit

class yourViewController: UIViewController {

func shareContentInFB(){


let content = FBSDKShareLinkContent()

      content.contentURL =URL(string: &#34;http://yourURL/&#34;)
      content.quote = &#34;Hey !!!!&#34;
      let dialog : FBSDKShareDialog = FBSDKShareDialog()
      dialog.fromViewController = self
      dialog.shareContent = content
      dialog.mode = FBSDKShareDialogMode.automatic
      dialog.show()
   }
}
</code></pre>

<p>你不能使用这个在 fb 中预填充文本,如果你必须这样做,那么使用 Fb graph API</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何使用 URLScheme 在 facebook 或 google 上分享帖子,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/48662440/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/48662440/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何使用 URLScheme 在 facebook 或 google 上分享帖子