【发布时间】:2014-05-05 15:01:15
【问题描述】:
我正在开发一个精灵套件游戏,我想在游戏结束时集成一个 Twitter 共享模块。
这是我在一个空场景上测试的 BASIC 代码:
@implementation gameOverScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.backgroundColor = [SKColor orangeColor];
}
return self;
}
-(void)showTweetSheet {
//Create an instance of the tweet sheet
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.completionHandler = ^ (SLComposeViewControllerResult result) {
switch (result) {
//the tweet was canceled
case SLComposeViewControllerResultCancelled:
break;
//the user hit send
case SLComposeViewControllerResultDone:
break;
}
};
//sets body of the tweet
[tweetSheet setInitialText:@"testing text"];
//add an image to the tweet
if (![tweetSheet addImage:[UIImage imageNamed:@"name.png"]]) {
NSLog(@"Unable to add the image!");
}
//add a URL to the tweet, you can add multiple URLS:
if (![tweetSheet addURL:[NSURL URLWithString:@"url.com"]]) {
NSLog(@"Unable to add the URL!");
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
//presents the tweet sheet to the user
[self presentViewController:tweetSheet animated:NO completion:^{
NSLog(@"tweet sheet has been presented");
}];
}
}
但是当用户点击场景时尝试呈现 tweetSheet 视图控制器时,我不断收到错误“使用未声明的标识符”。
如何将社交框架正确集成到我的项目中?可以在精灵套件上使用吗?
【问题讨论】:
-
tweetSheet在showTweetSheet方法中被声明为局部变量。也许这就是为什么当您尝试在单独的方法touchesBegan中使用它时,编译器会说“使用未声明的标识符”。 -
我就是这么想的,但我把它变成了一个全球性的,结果也一样:(@Anna
-
更新问题中的代码并展示您如何将其设为“全局变量”。
-
我不明白你的代码。在
touchesBegan中,调用 do:[self showTweetSheet]。即使这样,我实际上也不理解您的代码。寻找教程。 -
@Anna woops 我的意思是一个文件范围的实例变量,我把它放在大括号中的实现之后(现在删除它但它是 - implementation MyScene {SLComposeViewController *tweetSheet}
标签: ios objective-c twitter sprite-kit