Open file from local file system using default iOS application

I downloaded several files from the server and saved them to the local file system. I want to open them using the default application in the device. How to open files using the default application. Please provide some code examples.

thanks

+4
source share
1 answer

First you need to present the resource (the downloaded file to open) using the NSURL object. The following assumes an NSString named filePath, which is already initialized with the path to the resource open .

NSURL *resourceToOpen = [NSURL fileURLWithPath:filePath];

, , .

BOOL canOpenResource = [[UIApplication sharedApplication] canOpenURL:resourceToOpen];

, , .

if (canOpenResource) { [[UIApplication sharedApplication] openURL:resourceToOpen]; }

UIApplication canOpenURL:

, openURL: . , URL- .

, , UTI , - -

UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
documentController.delegate = self;
[documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

UIDocumentInteractionControllerDelegate. UTI .

+10

All Articles