我正在製作一個精靈套件遊戲,我想在遊戲結束時集成一個twitter共享模塊。如何解決這個分享按鈕?
這是基本的代碼,我嘗試了一個空的現場測試的東西:
@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
多數民衆贊成我認爲,但我做了一個全球性的,並有相同的結果:(@Anna – user3576196
更新問題中的代碼,並顯示你如何使它成爲一個「全局變量」。 – Anna