Last active
August 29, 2015 14:25
-
-
Save tadamatu/24cd5f42afd8ae58aac3 to your computer and use it in GitHub Desktop.
Lineへの投稿
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
//Lineのテキストを投稿 | |
void postLine(NSString *text) { | |
//アプリ:LINE に直接遷移して投稿 | |
text = [text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
NSString *LINEUrlString = [NSString stringWithFormat:@"line://msg/text/%@", text]; | |
//LINEインストールの確認 | |
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:LINEUrlString]]) { | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:LINEUrlString]]; | |
//LINEは投稿完了を受け取れないため、メソッドコールと投稿完了がイコールとなる | |
//投稿完了の処理 | |
} else { | |
//LINEがインストールされていない場合の処理 | |
} | |
} | |
//Lineのイメージを投稿 | |
void postLineImage(NSString *imageName) { | |
UIImage *image = [UIImage imageNamed:imageName]; | |
//iOS7.0以降では共有のクリップボードを使う必要がある | |
UIPasteboard *pasteboard; | |
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) { | |
pasteboard = [UIPasteboard generalPasteboard]; | |
} else { | |
pasteboard = [UIPasteboard pasteboardWithUniqueName]; | |
} | |
[pasteboard setData:UIImagePNGRepresentation(image) forPasteboardType:@"public.png"]; | |
NSString *LINEUrlString = [NSString stringWithFormat:@"line://msg/image/%@", pasteboard.name]; | |
//LINEインストールの確認 | |
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:LINEUrlString]]) { | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:LINEUrlString]]; | |
//LINEは投稿完了を受け取れないため、メソッドコールと投稿完了がイコールとなる | |
//投稿完了の処理 | |
} else { | |
//LINEがインストールされていない場合の処理 | |
} | |
} |
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