mike vorisis
mike vorisis

Reputation: 2832

Social Framework doesn't work properly Swift

I want to have a share button in my app for sharing to Facebook. I decided to do it with the social framework as i believed it was easier. I was wrong...

Here is my code:

@IBAction func facebookButton(sender: AnyObject) {
        if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
            let fbSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
            fbSheet.setInitialText("Some text")
            fbSheet.addImage(UIImage(named: "loading"))
            fbSheet.addURL(NSURL(string: "http://www.something.com"))
            presentViewController(fbSheet, animated: true, completion: nil)
        } else {
            self.showAlert("Facebook", msg: "Please login to your Facebook account in Settings")
        }
    } 

This code is working, but it returns only the url and if I comment it; it returns only the image. I have changed the order and I put image third but again it returns only the url. It's like it has priorities and it returns only one of them.

Upvotes: 0

Views: 643

Answers (1)

Konstantinos Natsios
Konstantinos Natsios

Reputation: 2924

Since last year Facebook doesn't allow to prefill the text if you want to share something. You can set only hashtags as setInitialText. something like this

fbSheet.setInitialText("#\(appname)")

https://developers.facebook.com/docs/apps/review/prefill

Upvotes: 2

Related Questions