画像を直接アップロードすることはできないのですが、自分のアプリからInstagramへ画像を渡す方法は存在します。
詳しくは公式ドキュメント (DOCUMENT INTERACTIONの部分)。
ポイントを列挙すると
- JPEG/PNGでファイルを保存
- 拡張子は.ig
- Document Interaction UTI がcom.instagram.photo
- 画像サイズは612px以上
@interface MyViewController : UIViewController
<UIDocumentInteractionControllerDelegate>
{
UIDocumentInteractionController *interactionController;
}
@property (nonatomic, retain) UIDocumentInteractionController *interactionController;
@end@implementation MyViewController
@synthesize interactionController;
- (void)openAppList {
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if (![[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSLog(@"Instagramがインストールされていない");
return;
}
NSString *filePath;
filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.ig"]; ;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
self.interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
interactionController.delegate = self;
BOOL present = [interactionController presentOpenInMenuFromRect:self.view.frame
inView:self.view
animated:YES];
if (!present) {
NSLog(@"このファイルを開けるアプリが存在しない。");
}
}
#pragma mark -
#pragma mark UIDocumentInteractionControllerDelegate
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
willBeginSendingToApplication:(NSString *)application
{
// アプリ送信前に呼ばれるデリゲートメソッド
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
didEndSendingToApplication:(NSString *)application
{
// アプリ送信後に呼ばれるデリゲートメソッド
}
- (void)dealloc {
[interactionController release];
[super dealloc];
}
@end実は上のコードを実行すると、EvernoteやDropboxのアプリをインストールしている場合、Instagramの他にEvernoteやDropboxも送信先の候補として挙がってきます。
おそらくこれらのアプリは「どんな種類のファイルでも受け入れる」という設定をしているためでしょうが、Instagramのみを候補にあげる方法は分かりませんでした。
また、UTIについてですが、ファイルの 拡張子をigにするとUIDocumentInteractionControllerは自動でUTIをcom.instagram.photoと認識してくれるようです。
[追記 2012/05/20]
Instagramのバージョンアップに伴って色々オプションが追加されているようです。
拡張子をigにするとInstagram以外にもJPEGとPNGファイルを扱えるアプリが選択肢として選べてしまうのですが
igoとすることでInstagramのみを候補に挙げることができるようになっています。
また、UIDocumentInteractionControllerのannotationプロパティの対応も追加されています。
interactionController.annotation = [NSDictionary dictionaryWithObject:@"入力済みのキャプション" forKey:@"InstagramCaption"];こうすることでキャプションに特定の文字を入力済みにできるようになっています。(Instagramのバージョンが2.1以上)





1 comments:
ぜひ、xprocess他のアプリを対応して欲しいです!
あと、xprocess他のアプリでも.igを開けるようにできると良いと思います。
そうすれば他アプリ→xprocess→instagramっていうのができないでしょうか?
素人考えですが(^^;;
コメントを投稿