Created
March 8, 2014 06:29
-
-
Save ken0nek/9426283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -(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