This class is part of the UIKit framework, which is included by the default xCode project setup so there is no need to link any additional framework.
This is what you need to do in terms of code:
1. Make your relevant class file conform to the UIDocumentInteractionControllerDelegate protocol and define a variable
Assuming your class is called ViewController, then in the ViewController.h file:
@interface ViewController : UIViewController <UIDocumentInteractionControllerDelegate>
{
UIDocumentInteractionController *docController;
}
2. Add the following methods in ViewController.m:
//- set up the UIDocumentInteraction controller and set its delegate to self so we can handle the callback events
- (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL
usingDelegate:(id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL:fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
//- the key instance method here is the presentOptionsMenuFromBarBUttonItem
//- it is assumed here that there is a BarButtonItem called _btnActions
- (void)showOptionsMenu
{
NSURL *fileURL = [NSURL fileURLWithPath:@"THE_FILE_URL_PATH"];
docController = [self setupControllerWithURL:fileURL
usingDelegate:self];
bool didShow = [docController presentOptionsMenuFromBarButtonItem:_btnActions
animated:YES];
if (!didShow) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"Sorry. The appropriate apps are not found on this device."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
}
3. Add a method to invoke the above when you want to show the apps that you could send the file to
In this example, a UIBarButton is wired up to the following IBActions:
- (IBAction)ActionButtonClicked:(id)sender {
[self showOptionsMenu];
}
That is it. When the button is clicked an action sheet will appear (all powered by the Apple's UIDocumentInteractionController class) that shows the apps (if any) that you could send the file to.
You can optionally implement the following delegate methods:
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller