首页 > 解决方案 > Flutter share facebook:“init()”已在此处明确标记为不可用(FBSDKShareKit.ShareDialog)

问题描述

我想将我的 Flutter 应用中的帖子分享到 Facebook 等社交媒体平台。

我使用了 flutter_share_me包(版本 1.2.0),我的 Android 项目在 Facebook 共享上运行良好。

但是当我构建我的iOS项目时,由于以下错误,构建失败

在 SwiftFlutterShareMePlugin.swift 文件的 sharefacebook 函数中。

'init()' 已在此处明确标记为不可用 (FBSDKShareKit.ShareDialog)

func sharefacebook(message:Dictionary<String,Any>, result: @escaping FlutterResult)  {
    let viewController = UIApplication.shared.delegate?.window??.rootViewController
    let shareDialog=ShareDialog() // **this line make the error**
    let shareContent = ShareLinkContent()
    shareContent.contentURL = URL.init(string: message["url"] as! String)!
    shareContent.quote = message["msg"] as? String
    shareDialog.mode = .automatic
    ShareDialog(fromViewController: viewController, content: shareContent, delegate: self).show()
    result("Sucess")

}

请帮助我解决这个问题。

我发现其他 Flutter 开发人员在尝试使用share_plus包等其他包将帖子分享到 Facebook 时也遇到了类似的问题

https://github.com/fluttercommunity/plus_plugins/issues/579

标签: iosswiftflutterdartfbsdksharekit

解决方案


我已经更新了 flutter_share_me 包(1.2.0 版)文件的 SwiftFlutterShareMePlugin.swift,如下所示,iOS 项目正在用于 facebook 共享。

func sharefacebook(message:Dictionary<String,Any>, result: @escaping FlutterResult)  {
    let viewController = UIApplication.shared.delegate?.window??.rootViewController
    
    let shareContent = ShareLinkContent()
    shareContent.contentURL = URL.init(string: message["url"] as! String)!
    shareContent.quote = message["msg"] as? String
    ShareDialog(viewController: viewController, content: shareContent, delegate: self).show()
    result("Sucess")
    
}

我认为问题是因为 FBSDKShareKit 的某些功能已被其版本升级弃用。


推荐阅读