Ben Bar
Ben Bar

Reputation: 85

Shared Text doesn't get shared to Facebook (but to others)

I have this code that shares a screenshot of the app, an initial Text and a URL via the Apple Share menu when a Share Button is pressed. It works like a charm with Twitter, Messages, Email etc, but when i wanna share to Facebook or the Facebook Messenger, the text doesn't show up (but the image and the URL do). Any idea why that is and how to fix it?

I was able to share text and a URL to Facebook with other functions (but they didn't deliver the right screenshot so i switched to this one).

Thanks in advance!

Edit: The text does get shared in the xcode Simulator, just not on the iPhone(s).

   func takeSnapshot(view: UIView) {
        let bounds = UIScreen.mainScreen().bounds
        UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0.0)
        self.view.drawViewHierarchyInRect(bounds, afterScreenUpdates: false)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        let text = "Text to be shared... #Hashtag"
        let URL = NSURL(string: "http://stackoverflow.com/")!
        let activityViewController = UIActivityViewController(activityItems: [image, text, URL], applicationActivities: nil)
        self.presentViewController(activityViewController, animated: true, completion: nil)

    }

Upvotes: 1

Views: 636

Answers (1)

AmD
AmD

Reputation: 499

An update to the Facebook application has replaced the in-built Facebook share activity with one that ignores status text - If you remove the Facebook app from your device the text will be displayed using the code you have. If you have the Facebook app installed you get images, URLs but not the text.

Follow the instructions: https://developers.facebook.com/docs/sharing/ios

Then you can do something like this:

Share a link

let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "<INSERT STRING HERE>")
content.contentTitle = "<INSERT STRING HERE>"
content.contentDescription = "<INSERT STRING HERE>"
content.imageURL = NSURL(string: "<INSERT STRING HERE>")

let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 25)
self.view.addSubview(button)

Share Photos

class ViewController: UIViewController, FBSDKLoginButtonDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate
 let button : UIButton = UIButton()
 button.backgroundColor = UIColor.blueColor()
 button.setTitle("Choose Photo", forState: .Normal)
 button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 150) * 0.5, 125, 150, 25)
 button.addTarget(self, action: "photoBtnClicked", forControlEvents: .TouchUpInside)
 self.view.addSubview(button)

 let label : UILabel = UILabel()
 label.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 200) * 0.5, 100, 200, 25)
 label.text = "Photos Example"
 label.textAlignment = .Center
 self.view.addSubview(label)

func photoBtnClicked(){
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){
        println("Photo capture")
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
        imagePicker.allowsEditing = false
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }   
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

    let photo : FBSDKSharePhoto = FBSDKSharePhoto()
    photo.image = info[UIImagePickerControllerOriginalImage] as! UIImage
    photo.userGenerated = true
    let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
    content.photos = [photo]
}

Photos must be less than 12 MB in size

Share Video on Facebook

class ViewController: UIViewController, FBSDKLoginButtonDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate
 let button : UIButton = UIButton()
 button.backgroundColor = UIColor.blueColor()
 button.setTitle("Choose Video", forState: .Normal)
 button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 150) * 0.5, 200, 150, 25)
 button.addTarget(self, action: "videoBtnClicked", forControlEvents: .TouchUpInside)
 self.view.addSubview(button)

 let label : UILabel = UILabel()
 label.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 200) * 0.5, 175, 200, 25)
 label.text = "Video Example"
 label.textAlignment = .Center
 self.view.addSubview(label)
 func videoBtnClicked(){
     if  UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSource Type.SavedPhotosAlbum){
         println("Video capture")
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePicker.allowsEditing = false
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }

}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

        let video : FBSDKShareVideo = FBSDKShareVideo()
        video.videoURL = info[UIImagePickerControllerMediaURL] as! NSURL
        let content : FBSDKShareVideoContent = FBSDKShareVideoContent()
        content.video = video
}

Videos must be less than 12MB in size. I hope I have helped you. (Sorry for my english)

Upvotes: 1

Related Questions