2014-05-04 69 views
2

我完全失去了,我發現的所有教程都是用於故事板的iOS 6應用程序。我的問題是如果你可以在sprite-kit遊戲中擁有twitter或者facebook分享功能嗎?如果是的話,添加它的最佳方式是什麼?我讀過的很多教程使用視圖控制器,但精靈套件使用場景,所以我有點困惑。在sprite-kit遊戲中可以有Twitter/Facebook分享按鈕嗎?

謝謝。

+0

作爲SKViews子類或者UIViews或NSViews我會去和使用「舊」技術。只需繼續(或顯示)UIViewController。 – Akaino

回答

1

這可能有所幫助。 ShareKit

這是一種將Facebook,Twitter和其他社交網絡服務整合到您的應用中的簡單方法。

11

這是twitter的答案。不客氣!

1)在Build Phases選項卡下導入Social框架,然後將Binary與庫鏈接。將這個代碼在你想要在分享它的SKScene頂部

#import <Social/Social.h> 

2)-(id)initWithSize:(CGSize)size方法與此代碼添加您的鳴叫按鈕:

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

3)在touchesBegan:方法把下面的代碼來處理一下鳴叫按鈕和作曲鳴叫

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