基于Spritekit的应用程序没有在共享到Facebook按钮中显示setInitialText

时间:2015-08-15 21:40:37

标签: swift sprite-kit social-framework

我目前在App Store上有一个基于Spritekit的游戏叫做Lil' Softy,它使用社交框架。我在应用程序中有两个按钮,允许用户分享到Facebook和Twitter。出于某种原因,当我触摸Facebook按钮时,我编码的初始文本不会显示,但它完全显示在Twitter按钮上。我已经花了好几个小时才弄清楚为什么会这样,我似乎无法理解。

这是点击Twitter或Facebook按钮时运行的代码:

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)
} 

这是我点按Twitter按钮时显示的内容:http://imgur.com/CMvhANk

这是我点击Facebook按钮时显示的内容:http://imgur.com/vcRDXbs

如果有人对此有任何解释,请告诉我,或者如果我需要提供更多信息,请告知我们。

1 个答案:

答案 0 :(得分:0)

Facebook应用程序的更新已将内置的Facebook共享活动替换为忽略状态文本的活动 - 如果您从设备中删除Facebook应用程序,将使用您拥有的代码显示文本。如果您安装了Facebook应用程序,则会获得图像,URL而不是文本。

按照说明操作:https://developers.facebook.com/docs/sharing/ios

然后你可以这样做:

分享链接

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)

分享照片

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]
}

照片的大小必须小于12 MB

在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
}

视频大小必须小于12MB。 我希望我能帮到你。 (对不起我的英文)