在SpriteKit游戏中发布Facebook帖子

时间:2016-05-30 19:02:59

标签: ios objective-c xcode sprite-kit social-framework

我可能有一个非常愚蠢的问题。我在SpriteKit游戏上工作,我希望用户能够在Facebook和Twitter上分享他们的Highscores。 帖子应包含文字和图片。 我的代码与Twitter合作但不与Facebook合作,我不知道为什么.. 这是Facebook的一部分:

#import <Social/Social.h>
...

SLComposeViewController *facebookSheet = [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook];

 facebookSheet.completionHandler = ^(SLComposeViewControllerResult result) {
        switch(result) {
            case SLComposeViewControllerResultCancelled:
                break;
            case SLComposeViewControllerResultDone:
                break;
        }
    };


[facebookSheet setInitialText:[_playerName stringByAppendingString: @" has a new Highscore"]];

[facebookSheet addImage:[UIImage imageNamed:_HighscoreImage]];

 UIViewController *controller = self.view.window.rootViewController;
    [controller presentViewController:facebookSheet animated: YES completion:nil];

1 个答案:

答案 0 :(得分:1)

  1. 如果安装了FB应用程序,则无法共享预填充文本
  2. 要解决此问题,我们可以选择FBSDKSharKit.Install FBSDK pod文件。

    if UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb:")!) {
        let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
    
        content.contentURL = NSURL(string: "https://google.com")
        content.contentTitle = "Test"
        content.contentDescription = "FBSDKShareKit is an alternative to this issue"
        content.imageURL = NSURL(string:"https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg")
    
        let ShareKit: FBSDKShareDialog = FBSDKShareDialog()
        ShareKit.fromViewController = self;
        ShareKit.shareContent = content
        ShareKit.mode = FBSDKShareDialogMode.FeedBrowser
        ShareKit.show()
    }
    
  3. 有关使用ShareKit的详细说明,请查看我的其他answer