OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使用 URLScheme 在 facebook 或 google 上分享帖子 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:43
标题: ios - 如何使用 URLScheme 在 facebook 或 google 上分享帖子

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

//For share twitter

let urlWhats = "twitter://post?message=\(fileURL)"
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 = "https://www.facebook.com/sharer/sharer.php?u=" + url

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

提前致谢



Best Answer-推荐答案


要在 FB 中分享,请使用“FacebookShare”

import FBSDKShareKit

class yourViewController: UIViewController {

func shareContentInFB()  {


let content = FBSDKShareLinkContent()

        content.contentURL =  URL(string: "http://yourURL/")
        content.quote = "Hey !!!!"
        let dialog : FBSDKShareDialog = FBSDKShareDialog()
        dialog.fromViewController = self
        dialog.shareContent = content
        dialog.mode = FBSDKShareDialogMode.automatic
        dialog.show()
     }
}

你不能使用这个在 fb 中预填充文本,如果你必须这样做,那么使用 Fb graph API

关于ios - 如何使用 URLScheme 在 facebook 或 google 上分享帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48662440/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4