2016-04-11 11 views
0

私は正常に上記のコードを使用して、ダウンロードしたiはコードIOSでダウンロードしたファイルをアプリで開く方法は?

NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,recFilName]; [nsdataFromBase64String writeToFile:filePath atomically:YES];

を使用しているような(PDFファイル、.txtファイル、.MP3など)などの様々なフォーマットのDATASをダウンロードしたアプリケーションを開発してい今、私はその拡張機能をサポートする適切なアプリケーションでダウンロードしたファイルを開く必要があります。

+0

「UIDocumentPickerViewController」を使用https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentPickerViewController_Class/ –

+0

@リチャード私は試してみます。 – Arun

+0

@リチャードは私が雲の中で何かしたいですか? – Arun

答えて

2

UIDocumentPickerViewControllerのインスタンスを作成し、そのデリゲートメソッドを実装する必要があります。

UIDocumentMenuViewController *documentPicker = 
[[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[<items>,...] 
      inMode:UIDocumentPickerModeOpen]; 
documentPicker.delegate = self; 
[self presentViewController:documentPicker animated:YES completion:nil]; 
0

ドキュメントピッカーを使用すると、ユーザーはアプリケーションのサンドボックス外のアイテムを選択できます。ファイルをダウンロードしてドキュメントディレクトリにローカルに保存する場合は、次のコードを参照してください。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
// Suppose you want to open downloaded PDF file 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"YourPDFFileName"]; 

NSURL *targetURL = [NSURL fileURLWithPath:filePath]; 
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; 

// Now load this request in WebView. 

同様に、他の形式も開くことができます。

+0

私はこの方法を試みましたが、web view.pdfでウォーキングしていない拡張子.3gpは魅力的です。 – Arun

+0

Media Playerでその3GPビデオファイルを開くことができます。以下を参照してください。 http://stackoverflow.com/questions/1535836/video-file-formats-supported-in-iphone MPMoviePlayerControllerが推奨されていないため、AVPlayerを使用する必要があります... Store 3gpローカルにファイルを開き、AVPlayerを使用して開きます。 – iCoder

関連する問題