Skip to content

Instantly share code, notes, and snippets.

@kazuph
Created June 8, 2014 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuph/de3b4f8ca66ae9e438b4 to your computer and use it in GitHub Desktop.
Save kazuph/de3b4f8ca66ae9e438b4 to your computer and use it in GitHub Desktop.
iOSのOS登録情報を使って認証なしでFacebook・Twitterでシェアする(LINEも追加) ref: http://qiita.com/kazuph/items/b1c98b4837dd1a161851
#import "Social.h"
・・・
[Social facebookShare:self];
or
[Social twitterShare:self];
or
[Social lineShare:self];
#import <Foundation/Foundation.h>
@interface Social : NSObject
+(void)facebookShare:(UIViewController *)vc;
+(void)twitterShare:(UIViewController *)vc;
+(void)lineShare:(UIViewController *)vc;
@end
#import "Social.h"
#import <Social/Social.h>
@implementation Social
+(void)facebookShare:(UIViewController *)vc
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
void (^completion) (SLComposeViewControllerResult result) = ^(SLComposeViewControllerResult result) {
[composeViewController dismissViewControllerAnimated:YES completion:nil];
};
[composeViewController setCompletionHandler:completion];
[composeViewController setInitialText:@"テスト"];
[composeViewController addURL:[NSURL URLWithString:@"http://google.com"]];
[vc presentViewController:composeViewController animated:YES completion:Nil];
}
}
+(void)twitterShare:(UIViewController *)vc
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
void (^completion) (SLComposeViewControllerResult result) = ^(SLComposeViewControllerResult result) {
[composeViewController dismissViewControllerAnimated:YES completion:nil];
};
[composeViewController setCompletionHandler:completion];
[composeViewController setInitialText:@"テスト"];
[composeViewController addURL:[NSURL URLWithString:@"http://google.com"]];
[vc presentViewController:composeViewController animated:YES completion:Nil];
}
}
+(void)lineShare:(UIViewController *)vc {
NSString *plainString = @"テスト";
NSString *contentKey = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)plainString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );
NSString *contentType = @"text";
NSString *urlString = [NSString stringWithFormat: @"http://line.naver.jp/R/msg/%@/?%@", contentType, contentKey];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment