LoginSignup
6
4

More than 5 years have passed since last update.

【iOS】UIDocumentInteractionControllerでアプリのDocuments配下ファイルを別のアプリに託す

Posted at

iOSアプリで、自分のアプリで作成・保存したファイルを他のアプリで開く操作。
URLスキームではなく、渡すファイルだけ指定して後はOSによろぴこする方法です。

UIDocumentInteractionController

サンプルはPDFファイルを渡しています。
以下コード

実装.m

// URLはフルパス(今回はDocumentsフォルダ内のファイル)
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask,
                                                         YES);
NSString *docPath = [arrayPaths objectAtIndex:0];
NSString *fullPath = [path stringByAppendingPathComponent:@"xxx.pdf"];
NSURL *url = [NSURL fileURLWithPath:fullPath];

// URLを使ってUIDocumentInteractionControllerを生成
UIDocumentInteractionController docInteractionController= [UIDocumentInteractionController interactionControllerWithURL:url];

// UIDocumentInteractionControllerDelegateをセット
docInteractionController.delegate = self;

// 委譲開始
// 第一引数でアプリ選択ポップアップの表示位置を設定
BOOL result = [docInteractionController presentOptionsMenuFromRect:CGRectZero
                                     inView:self.view animated:YES];

if (!result){
    // ファイルを開けるアプリが存在しなかったら返り値がfalse
}
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4