[英]Is it possible to have a Twitter / Facebook share button in a sprite-kit game?
I'm completely lost, all the tutorials I've found have been for iOS 6 apps with Storyboards. 我完全迷失了,我发现的所有教程都是针对带有Storyboard的iOS 6应用程序。 My question is if you can have a twitter or facebook sharing feature in a sprite-kit game? 我的问题是你是否可以在sprite-kit游戏中拥有推特或Facebook共享功能? 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. 我读过的很多教程都使用了viewcontrollers,但sprite-kit使用了场景,所以我有点困惑。
Thanks. 谢谢。
Here is an answer for twitter. 这是twitter的答案。 Your Welcome! 别客气!
1) import the Social framework under the Build Phases tab then Link Binary with Libraries. 1)在Build Phases选项卡下导入Social框架,然后在Link Binary和Libraries中导入。 Put this code at the top of your SKScene that you want to share it in. 将此代码放在您要共享的SKScene顶部。
#import <Social/Social.h>
2) add your tweet button in the -(id)initWithSize:(CGSize)size
method with this code: 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) in your touchesBegan:
method put the following code to handle clicking the tweet button and composing a tweet 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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.