Skip to content

Instantly share code, notes, and snippets.

@ken0nek
Created March 8, 2014 06:29
Show Gist options
  • Select an option

  • Save ken0nek/9426283 to your computer and use it in GitHub Desktop.

Select an option

Save ken0nek/9426283 to your computer and use it in GitHub Desktop.
-(IBAction)postToTwitter{
// ServiceTypeをTwitterに設定
NSString *serviceType = SLServiceTypeTwitter;
// Twitterが利用可能かチェック
if ([SLComposeViewController isAvailableForServiceType:serviceType]) {
// SLComposeViewControllerを初期化・生成
SLComposeViewController *twitterPostVC = [[SLComposeViewController alloc] init];
// ServiceTypeをTwitterに設定
twitterPostVC = [SLComposeViewController composeViewControllerForServiceType:serviceType];
// 初期テキストの設定
[twitterPostVC setInitialText:@"#LITech #TechCamera"];
// 画像の追加
[twitterPostVC addImage:imageView.image];
// 投稿の可否
[twitterPostVC setCompletionHandler:^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultDone) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"投稿を完了しました"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"投稿できませんでした"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}];
// SLComposeViewControllerのViewを表示
[self presentViewController:twitterPostVC animated:YES completion:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment