【问题标题】:Swift 5 IOS facebook share dialog, is not showing on my appSwift 5 IOS facebook 分享对话框,未显示在我的应用程序上
【发布时间】:2020-04-12 12:19:39
【问题描述】:

我有一周的时间尝试从 facebook 显示 shareDialog,但没有任何效果, 我的登录按钮正在工作,我在 Android 中的工作正常,但 IO 无法正常工作,我已经从 Facebook 安装了我的 SDK,我将所有文件夹 Bolt 放入项目中,但似乎没有什么对我有用,我已经为facebookSDK https://github.com/facebookarchive/facebook-swift-sdk/blob/master/MigrationGuide.md进行了迁移

并且不起作用,我做错了什么,这是我的 AppDelegate.swift:

import UIKit
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // Override point for customization after application launch.

        ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )
        return true
    }

    func application(
        _ app: UIApplication,
        open url: URL,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]
    ) -> Bool {
        return ApplicationDelegate.shared.application(
            app,
            open: url,
            options: options
        )
    }
    func applicationDidBecomeActive(_ application: UIApplication) {
        AppEvents.activateApp()
    }



    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }


}

这里是 ViewController.swift:

import UIKit
import FBSDKLoginKit
import FBSDKShareKit


class ViewController: UIViewController {

    @IBAction func ShareButton(_ sender: Any) {
        let alert = UIAlertController(title : "Comparte", message:"Comparte con amigos", preferredStyle: .actionSheet)

        let actionOne = UIAlertAction(title: "Comparte en facebook", style: .default) { (UIAlertAction) in

            let sharePhoto = SharePhoto()
            sharePhoto.imageURL = URL(string: "https://www.hola.com/imagenes/actualidad/20171204102954/adelanto-portada-revista-hola/0-514-626/adelanto-hola1-t.jpg")

            let content = SharePhotoContent()
            content.photos = [sharePhoto]

            self.showShareDialog(content)

        }
        alert.addAction(actionOne)

       self.present(alert, animated: true, completion: nil)

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let loginButton = FBLoginButton(permissions: [ .publicProfile ])
        loginButton.center = view.center

        view.addSubview(loginButton)
        // Do any additional setup after loading the view.
    }

     func showShareDialog<C: SharingContent>(_ content: C, mode: ShareDialog.Mode = ShareDialog.Mode.automatic) {
        let dialog = ShareDialog(fromViewController: self, content: content, delegate: self as? SharingDelegate)
            dialog.mode = mode

            dialog.show()
    }

     func sharer(_ sharer: Sharing, didCompleteWithResults results: [String: Any]) {
        print("success")

        let title = "Share Success"
        let message = "Thank You"
        let alertController = UIAlertController.init(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
        self.present(alertController, animated: true, completion: nil)


    }

    func sharer(_ sharer: Sharing, didFailWithError error: Error) {
        print("error")

        let title = "Share Failed"
        let message = "Something went wrong. Please try again"
        let alertController = UIAlertController.init(title: title, message: message, preferredStyle: UIAlertController.Style.actionSheet)
        self.present(alertController, animated: true, completion: nil)
    }

    func sharerDidCancel(_ sharer: Sharing) {
        print("canceled")

        let title = "Share Cancelled"
        let message = "Share on Facebook was Cancelled"
        let alertController = UIAlertController.init(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
        self.present(alertController, animated: true, completion: nil)
    }


}
```

【问题讨论】:

  • 请问您找到解决方案了吗?

标签: ios swift facebook fbsdksharedialog


【解决方案1】:

提出一个问题我找到了一些答案,所以我用带有链接内容的共享对话框制作了它,问题在于内容的创建,我解决了链接内容的问题,我会尝试其他类型的内容,我将向您展示如何完成,同时,这里是正确的代码和正确的内容,记住这是 swift 5

let content = ShareLinkContent()

        let api = "https://developers.facebook.com"
        let endpoint = "/"
        let url = URL(string: api + endpoint)
        content.contentURL = url!

        let dialog = ShareDialog(fromViewController: self, content: content, delegate: self as? SharingDelegate)
        dialog.mode = mode
        print(dialog.canShow)
        dialog.show()

【讨论】:

  • 但这并不能解决问题,因为我想分享一个视频,而不仅仅是一个链接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-23
  • 2013-05-31
  • 2013-05-26
  • 2018-11-02
  • 1970-01-01
相关资源
最近更新 更多