0

I am developing a app in which i downloaded datas of various format such as (.pdf,.txt,.mp3 etc) i have used the code

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

I successfully downloaded by using the above code, Now i have to open the downloaded files with the appropriate app that supports that extension can any one help me with the code.

Arun
  • 659
  • 9
  • 24

2 Answers2

2

You need to create an instance of UIDocumentPickerViewController and implement its delegate methods.

UIDocumentMenuViewController *documentPicker =
[[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[<items>,...]
            inMode:UIDocumentPickerModeOpen];
documentPicker.delegate = self;
[self presentViewController:documentPicker animated:YES completion:nil];
Mahendra
  • 7,012
  • 2
  • 25
  • 50
0

Document picker allows user to select the items outside the App's sandbox. If you are downloading the files and storing it locally on your documents directory please see below code ..

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.

Similarly you can open other formats as well.

iCoder
  • 1,260
  • 9
  • 25
  • I tried this method but .3gp extension not woking in web view.pdf is working in a charm. – Arun Apr 22 '16 at 10:44
  • You can open that 3GP video files in Media player. See following might help you.. http://stackoverflow.com/questions/1535836/video-file-formats-supported-in-iphone You'll have to use AVPlayer now as MPMoviePlayerController is deprecated... Store 3gp file locally and open it using AVPlayer.. Hope this helps – iCoder Apr 25 '16 at 06:45