Skip to content

Instantly share code, notes, and snippets.

@tadamatu
Created July 22, 2015 14:26
Show Gist options
  • Save tadamatu/643404d6861ea7ae513c to your computer and use it in GitHub Desktop.
Save tadamatu/643404d6861ea7ae513c to your computer and use it in GitHub Desktop.
Twitterの投稿
//Twitterの投稿
//※Social.frameworkの追加が必要(iOS6.0以上の場合)
//※Twitter.frameworkの取り込みが必要(iOS5.0以下の場合)
void postTwitter(NSString *text, NSString *url, NSString *image) {
NSURL* appURL = [NSURL URLWithString:url];
// iOS Version
NSString *iosVersion = [[[UIDevice currentDevice] systemVersion] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// Social.frameworkを使う
if ([iosVersion floatValue] >= 6.0) {
SLComposeViewController *twitterPostVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterPostVC setInitialText:text];
[twitterPostVC addURL:appURL];
[twitterPostVC addImage:[UIImage imageNamed:image]];
[twitterPostVC setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
//投稿完了の処理
}
}];
[ViewController presentViewController:twitterPostVC animated:YES completion:nil];
}
// Twitter.frameworkを使う
else if ([iosVersion floatValue] >= 5.0) {
TWTweetComposeViewController* twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:text];
[twitter addURL:appURL];
[twitter addImage:[UIImage imageNamed:image]];
[twitter setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
//投稿完了の処理
}
}];
[ViewController presentViewController:twitter animated:YES completion:nil];
}
}
@tadamatu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment