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

标签 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)
}

提前致谢

最佳答案

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

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

相关文章:

ios - 在 iOS 上扫描蓝牙 2.1(旧版)设备

ios - 通知画外音用户他们已突出显示容器中的元素

ios - 转换 Controller 动画 - 条件中的变量绑定(bind)需要初始值设定项

ios - 如何在 Swift 中初始化 UIView?

swift - 根据注释的属性设置注释的字形文本

首次 Facebook Connect 授权/登录后 iPhone 应用程序崩溃

css - Facebook 自定义样式 : visibility hidden works, 显示 none 不

facebook - 如何将 Facebook 测试页面订阅到 Messenger 应用程序

ios - 行为类似于 NSUserDefaults 的 iCloud 键值存储

ios - 选项卡式应用程序 - 如何隐藏选项卡栏