Sprite-Kit游戏中可以有一个Twitter/Facebook共享按钮吗? [英] Is it possible to have a Twitter / Facebook share button in a sprite-kit game?

查看:71
本文介绍了Sprite-Kit游戏中可以有一个Twitter/Facebook共享按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全迷路了,我找到的所有教程都是针对带有Storyboards的iOS 6应用的.我的问题是您是否可以在Sprite-Kit游戏中具有Twitter或Facebook共享功能?如果是这样,添加它的最佳方法是什么?我看过的许多教程都使用viewcontrollers,但是sprite-kit使用场景,所以我有点困惑.

I'm completely lost, all the tutorials I've found have been for iOS 6 apps with Storyboards. My question is if you can have a twitter or facebook sharing feature in a sprite-kit game? If so what is the best way to go about adding it? Alot of the tutorials I've read over use viewcontrollers but sprite-kit uses scenes so I'm a bit confused.

谢谢.

推荐答案

以下是Twitter的答案.欢迎您!

Here is an answer for twitter. Your Welcome!

1)在构建阶段"选项卡下导入社交"框架,然后将二进制链接到库".将此代码放在要共享它的SKScene的顶部.

1) import the Social framework under the Build Phases tab then Link Binary with Libraries. Put this code at the top of your SKScene that you want to share it in.

#import <Social/Social.h>   

2)使用以下代码在-(id)initWithSize:(CGSize)size方法中添加您的tweet按钮:

2) add your tweet button in the -(id)initWithSize:(CGSize)size method with this code:

SKSpriteNode *tweetButton = [SKSpriteNode spriteNodeWithImageNamed:@"share"];
tweetButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-150);
tweetButton.name = @"tweet";
[self addChild:tweetButton];

3)在您的touchesBegan:方法中,将以下代码用于处理单击tweet按钮并撰写tweet

3) in your touchesBegan: method put the following code to handle clicking the tweet button and composing a tweet

if ([node.name isEqualToString:@"tweet"]) {
    //  Create an instance of the Tweet Sheet
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:
                                           SLServiceTypeTwitter];

    // Sets the completion handler.  Note that we don't know which thread the
    // block will be called on, so we need to ensure that any required UI
    // updates occur on the main queue
    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
        switch(result) {
                //  This means the user cancelled without sending the Tweet
            case SLComposeViewControllerResultCancelled:
                break;
                //  This means the user hit 'Send'
            case SLComposeViewControllerResultDone:
                break;
        }
    };

    //  Set the initial body of the Tweet
    [tweetSheet setInitialText:@"This is my tweet text!"];

    //  Adds an image to the Tweet.  Image named image.png
    if (![tweetSheet addImage:[UIImage imageNamed:@"image.png"]]) {
        NSLog(@"Error: Unable to add image");
    }

    //  Add an URL to the Tweet.  You can add multiple URLs.
    if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
        NSLog(@"Error: Unable to URL");
    }
    UIViewController *controller = self.view.window.rootViewController;
    [controller presentViewController:tweetSheet animated: YES completion:nil]; 
}

这篇关于Sprite-Kit游戏中可以有一个Twitter/Facebook共享按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆