我有一个项目使用Twitter API来推动用户获得高分。该项目是使用Cocos2d v1.1编写的,一切正常。我最近使用Cocos2d v2.0开始了一个新项目,并试图使用我的其他项目中的相同代码来合并相同的Twitter功能,但是当按下Tweet按钮时,viewcontroller不会出现。以下是我正在使用的代码...
if ([TWTweetComposeViewController canSendTweet]) // Check if twitter is setup and reachable
{
CCLOG(@"Can Tweet");
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// set initial text
NSString *theTweet = @"The message..."];
[tweetViewController setInitialText:theTweet];
// setup completion handler
tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if(result == TWTweetComposeViewControllerResultDone) {
// the user finished composing a tweet
} else if(result == TWTweetComposeViewControllerResultCancelled) {
// the user cancelled composing a tweet
}
[viewController dismissViewControllerAnimated:YES completion:nil];
};
// present view controller
[[[CCDirector sharedDirector] openGLView] addSubview:viewController.view];
[viewController presentViewController:tweetViewController animated:YES completion:nil];
}
else
{
// Twitter account not configured, inform the user
NSLog(@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup");
}
我发现“openGLView”现已折旧,我已将其替换为“view”。这仍然不起作用。虽然该方法正在解雇。我已经包含了一个CCLOG,它返回字符串“Can Tweet”并出现在输出窗口中。有没有人对如何使这个工作有任何建议。如果我需要提供更多信息,请告诉我。
由于
答案 0 :(得分:1)
在cocos2d 2.0中使用此代码
AppController * app = (((AppController*) [UIApplication sharedApplication].delegate));
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[tweetViewController setInitialText:string];
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
dispatch_async(dispatch_get_main_queue(), ^{
{
if (result == TWTweetComposeViewControllerResultDone)
{
//successful
[[NSNotificationCenter defaultCenter] postNotificationName:@"PPTweetSuccessful" object:nil];
}
else if(result == TWTweetComposeViewControllerResultCancelled)
{
//Cancelled
}
}
[app.navController dismissModalViewControllerAnimated:YES];
[tweetViewController release];
});
}];
[app.navController presentModalViewController:tweetViewController animated:YES];