0

I would like to enable users in my app to share certain content on their facebook page such as: url, photo, text. This is the only piece of documentation that I could find on facebook website. I can't find any proper tutorial.
Do I need to add any method in App Delegate to configure facebook sdk?

What is the type of myContent ? I don't know where to start.

import FacebookShare

let shareDialog = ShareDialog(content: myContent) 
shareDialog.mode = .Native 
shareDialog.failsOnInvalidData = true 

shareDialog.completion = { result in    // Handle share results }

try shareDialog.show()

pods spec

Installing Bolts (1.9.0)
Installing FBSDKCoreKit (4.38.0)
Installing FBSDKLoginKit (4.38.0)
Installing FBSDKShareKit (4.38.0)
Installing FacebookCore (0.5.0)
Installing FacebookLogin (0.5.0)
Installing FacebookShare (0.5.0)
bibscy
  • 2,598
  • 4
  • 34
  • 82

1 Answers1

1

There is a difference between Message Dialog and Share Dialog, the message dialog opens the messenger app with the content, and the share dialog opens the share option in the facebook app, from your code it looks like you are trying to open the share option so you should edit the question title, secondly myContent is a type of object that conforms to the ContentProtocol, for example like you said sharing a url, you need to create a LinkShareContent, here is an example:

let linkContent = LinkShareContent(url: URL(string: "https://www.google.com/")!, quote: nil)

    let shareDialog = ShareDialog(content: linkContent)

    shareDialog.completion = { result in
        // Handle share results
    }

    do {
        try shareDialog.show()
    } catch {
        print(error)
    }

note: for a photo you can create a PhotoShareContent.

Arie Pinto
  • 1,274
  • 1
  • 11
  • 19
  • I get error Use of unresolved identifier `LinkShareContent` , Use of unresolved identifier `ShareDialog` – bibscy Nov 08 '18 at 16:44
  • make sure you have all of these pods: pod 'FacebookCore', pod 'FacebookShare', pod 'FBSDKMessengerShareKit'. clean and rebuild your project. – Arie Pinto Nov 08 '18 at 16:46
  • And if I want to share url, text and photo in the same post, how do I do that? – bibscy Nov 08 '18 at 16:51
  • Not quite sure, i haven't dived that deep into this SDK myself, but search for objects that confrom to the `ContentProtocol` and give them a try, maybe the `GraphSharer` not sure. who knows maybe its not even an option :) – Arie Pinto Nov 08 '18 at 16:56