Spritekit based app not displaying a setInitialText in a share to Facebook button

178 views Asked by At

I currently have a Spritekit-based game up on the App Store called Lil' Softy and it uses the Social Framework. I have two buttons in the app that allow the user to share to Facebook and Twitter. For some reason when I touch the Facebook button, the initial text that I have coded does not display, but it displays perfectly for the Twitter button. I've been trying for hours to figure out why this is happening and I can't seem to understand.

This is the code that runs when the Twitter or Facebook button is tapped:

func shareToFacebook(){
    var currentPoints = DDPointsLabel(num:NSUserDefaults.standardUserDefaults().integerForKey("points"))
    var currentPointsNumber = currentPoints.number
    var shareToFacebook: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
    shareToFacebook.setInitialText("Just caught \(currentPointsNumber) tears in #LilSofty https://itunes.apple.com/us/app/lil-softy/id1027535939?mt=8")
    shareToFacebook.addImage(UIImage(named: "LilSofty1024.png"))
    let vc: UIViewController = self.view!.window!.rootViewController!
    vc.presentViewController(shareToFacebook, animated: true, completion: nil)
}

func shareToTwitter(){
    var currentPoints = DDPointsLabel(num:NSUserDefaults.standardUserDefaults().integerForKey("points"))
    var currentPointsNumber = currentPoints.number
    var shareToTwitter: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
    shareToTwitter.setInitialText("Just caught \(currentPointsNumber) tears in #LilSofty https://itunes.apple.com/us/app/lil-softy/id1027535939?mt=8")
    shareToTwitter.addImage(UIImage(named: "LilSofty1024.png"))
    let vc1: UIViewController = self.view!.window!.rootViewController!
    vc1.presentViewController(shareToTwitter, animated: true, completion: nil)
} 

This is what it shows when I tap the Twitter button: https://i.stack.imgur.com/b2qgR.jpg

And this is what it shows when I tap the Facebook button: https://i.stack.imgur.com/HAKRS.jpg

If anyone has any explanation for this please let me know, or let me know if I need to supply more information.

1

There are 1 answers

0
AmD On

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)