I have written a simple Xcode project in swift for my iPhone . I am trying to send the text of my label to facebook using facebook share option .
Below is my code
import UIKit
import Social
class ViewController: UIViewController {
@IBOutlet weak var musicDescription: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func faceBookShareButton(sender: UIButton) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
let fbShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
let text = musicDescription.text
fbShare.setInitialText(text)
self.presentViewController(fbShare, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
But i am not able to see the text of the label in my facebook timeline. Someone guide me here . Why is the text not posting in facebook ?
Edit:Update I downloaded FBSDK files and added them to my project . I imported FBSDKShareKit into my ViewController.h file.
Here is my code
@IBAction func faceBookShareButton(sender: UIButton) {
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb:")!) {
var content: FBSDKShareLinkContent = FBSDKShareLinkContent()
var Subject: String = String(format: "FBSDKShareKit is an alternative to this issue")
content.contentTitle = "FBSDKShareKit"
content.contentDescription = Subject
var dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.shareContent = content
dialog.mode = FBSDKShareDialogModeWeb
dialog.show()
}
I am getting an error "Use of unresolved identifier FBSDKShareDialogModeWeb" . Anyone help please !