Created
July 22, 2015 14:26
-
-
Save tadamatu/643404d6861ea7ae513c to your computer and use it in GitHub Desktop.
Twitterの投稿
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
//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]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://tadamatu.blogspot.jp/2015/07/ios.html