我完全迷失了,我找到的所有教程都是针对带有故事板的 iOS 6 应用程序。我的问题是你是否可以在精灵套件游戏中拥有 Twitter 或 Facebook 共享功能?如果是这样,添加它的最佳方法是什么?我读过的很多教程都使用视图控制器,但 sprite-kit 使用场景,所以我有点困惑。
Thanks.
这是推特的答案。别客气!
1) 在“构建阶段”选项卡下导入社交框架,然后将二进制文件与库链接。将此代码放在您想要共享的 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];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)