DmitriyYefremov
DmitriyYefremov

Reputation: 35

Can't add description and title to url using Facebook share link content

I try add description and title for share link content . I am using pod 'FacebookShare' (because when i using FBSDKShareKit, description and title are deprecated)

https://i.sstatic.net/9p9lp.jpg

This my code with 'FacebookShare' :

        do{
            var myContent: LinkShareContent = LinkShareContent(url: NSURL(string:contentUrl!) as! URL )
            myContent.description = "Some description"
            myContent.title = "Hello"

            let shareDialog = ShareDialog(content: myContent)
            shareDialog.mode = .shareSheet
            shareDialog.presentingViewController = self
            shareDialog.failsOnInvalidData = true
            shareDialog.completion = { result in
                // Handle share results
            }
                try shareDialog.show()
            } catch {
                print("Error: \(error)")
         }

But i can see description and title only when i using : shareDialog.mode = .native In all other cases( .shareSheet, .Web, .Browser, .FeedWeb, .FeedBrowser) they don't added. I am not want use .native mode because not everyone has native Facebook app. Is there any solution for my case?

****UPDATE:****

set up the proper meta tags on the site (which is i sharing url) itself for title, description and image values and for other variables.

Upvotes: 2

Views: 2405

Answers (4)

Kishore Kumar
Kishore Kumar

Reputation: 4375

var content = LinkShareContent.init(url: URL.init(string: url)!) 

content.quote = "your content here"

Note in latest update description and title is deprecated so please use this instead that . don't forgot to import FacebookShare .

Upvotes: 0

user951315
user951315

Reputation:

I had the same issue - title, description and imageUrl are deprecated and readonly in the latest Facebook SDK version. I just downloaded an old one from April 2017 and it's working as expected.

Upvotes: 1

kkakkurt
kkakkurt

Reputation: 2800

You should update your myContent and shareDialog parts like this:

        let myContent:FBSDKShareLinkContent = FBSDKShareLinkContent()
        myContent.contentTitle = "Hello"
        myContent.contentDescription = "Test message"
        myContent.contentURL = (URL(string: "https://developers.facebook.com"))

        let shareDialog = FBSDKShareDialog()
        shareDialog.mode = .shareSheet
        FBSDKShareDialog.show(from: self, with: myContent, delegate: nil)

You can also import and use Social library for creating Facebook share box. And control your share results with Facebook share delegate functions. Like this way:

import FBSDKShareKit
import Social

class YourViewController: UIViewController, FBSDKSharingDelegate {
    func facebookShareButtonClicked() {
        let vc = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
        vc?.add(UIImage(named: "YourImageName"))
        vc?.add(URL(string: "https://developers.facebook.com")) //Your custom URL
        vc?.setInitialText("Your sample share message...")
        self.present(vc!, animated: true, completion: nil)
    }

//Facebook share delegate functions:
    func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) {
        print("Success")
    }

    func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) {
        print("didFailWithError: ", error)
    }

    func sharerDidCancel(_ sharer: FBSDKSharing!) {
        print("Sharer cancelled")
    }
}

Note: Try it with your device. It doesn't work on simulator. And be sure that the Facebook App is installed your device.

Upvotes: 0

Shivang Agarwal
Shivang Agarwal

Reputation: 1923

The methods that allow attaching a link to posts now retrieve the image, the title and the description from proprietary meta tags and not from the code itself. Simply remove the lines to get rid of the warnings and set up the proper tags on the site itself.

See the exact deprecation changelog here:

https://developers.facebook.com/docs/apps/changelog#v2_9_deprecations

Upvotes: 2

Related Questions