如何使用URLScheme在Facebook或谷歌上分享帖子

时间:2018-02-07 11:15:13

标签: ios swift facebook google-plus share

我想在Facebook上分享一个HTML链接,而不需要像WhatsApp或twitter这样的安装SDK。我使用下面的代码在Facebook上分享链接。但我想在没有开放的Safari浏览器的情况下分享帖子直接应用。 请告诉我这是否可能。我已经搜索了很多但没有找到任何解决方案。

//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)
}

先谢谢

1 个答案:

答案 0 :(得分:0)

要在FB中分享,请使用'

;

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图形API