Skip to content

Instantly share code, notes, and snippets.

@tanapon
Last active December 11, 2015 18:19
Show Gist options
  • Save tanapon/4641089 to your computer and use it in GitHub Desktop.
Save tanapon/4641089 to your computer and use it in GitHub Desktop.
Twitter native iOS 5.0+ sharing dialog class method for Cocos2D 2.0+
+(void)displayTweetComposerWithInitialText:(NSString*)initialText
successBlock:(void(^)())successBlock
cancelBlock:(void(^)())cancelBlock
{
if ([TWTweetComposeViewController canSendTweet]) // Check if twitter is setup and reachable
{
AppController *app = (AppController*)[[UIApplication sharedApplication] delegate];
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[tweetViewController setInitialText:initialText];
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
dispatch_async(dispatch_get_main_queue(), ^{
{
if (result == TWTweetComposeViewControllerResultDone)
{
//successful
if (successBlock != nil) {
successBlock();
}
}
else if(result == TWTweetComposeViewControllerResultCancelled)
{
//Cancelled
if (cancelBlock != nil) {
cancelBlock();
}
}
}
[app.navController dismissModalViewControllerAnimated:YES];
});
}];
[app.navController presentModalViewController:tweetViewController
animated:YES];
} else {
// Twitter account not configured, inform the user
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Sorry"
message:@"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"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment