I am developing a wrapper application for a site. Basically, it opens mobile version of a site in UIWebView. Some links on the site point to PDFs.
When the same site is
(Answered again as my previous answer did not include code. Apologies)
For a solution that fixed my issue I found a great example here.
I have cut and pasted it here incase it helps someone. Full credit to absoluteripple.com
Assuming your class is called ViewController, then in the ViewController.h file:
@interface ViewController : UIViewController { UIDocumentInteractionController *docController; }
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
//- the key instance method here is the presentOptionsMenuFromBarBUttonItem //- it is assumed here that there is a BarButtonItem called _btnActions- (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL usingDelegate:(id
) interactionDelegate { UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; interactionController.delegate = interactionDelegate; return interactionController; }
- (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]; } }
- (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