メモ
事前にProject>TARGET>Build Phases>Link Binaly With Libraries
で、Social.framework
を追加しておく。
↑LINEだけなら必要ないです。
Social.h
#import <Foundation/Foundation.h>
@interface Social : NSObject
+(void)facebookShare:(UIViewController *)vc;
+(void)twitterShare:(UIViewController *)vc;
+(void)lineShare:(UIViewController *)vc;
@end
Social.m
#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
呼び出し時
SampleViewController.m
#import "Social.h"
・・・
[Social facebookShare:self];
or
[Social twitterShare:self];
or
[Social lineShare:self];