Skip to content

Instantly share code, notes, and snippets.

@tadamatu
Last active August 29, 2015 14:25
Show Gist options
  • Save tadamatu/24cd5f42afd8ae58aac3 to your computer and use it in GitHub Desktop.
Save tadamatu/24cd5f42afd8ae58aac3 to your computer and use it in GitHub Desktop.
Lineへの投稿
//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がインストールされていない場合の処理
}
}
@tadamatu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment