0

I am trying to open pdf file in UIDocumentInteractionController.UIDocumentInteractionController open pop up menu but enter image description here When I select the any app than my application it is crashed but not displaying any error

here is my thread enter image description here

here is my .h file

#import <UIKit/UIKit.h>
#import "REFrostedViewController.h"
@interface download : UIViewController<UITableViewDelegate,UITableViewDataSource,UIDocumentInteractionControllerDelegate>
- (IBAction)menu:(id)sender;
@property (strong, nonatomic) IBOutlet UITableView *tbl_download;

@end

.m file

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    NSString *pdfFilePath= [documentsDir stringByAppendingPathComponent:[filePathsArray objectAtIndex:indexPath.row]];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:pdfFilePath error:NULL];
    NSLog(@"pdf path=%@",pdfFilePath);// your yourPdfFile file here
    NSURL *url = [NSURL fileURLWithPath:pdfFilePath];

    //create documentInteractionController here
    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];
    //set delegate
     [docController setDelegate:self];
    //provide button's frame from where popover will be lauched

    CGRect rect = CGRectMake(0, 0, 0, 0);
    [docController presentOpenInMenuFromRect:rect inView:self.view animated:YES];
}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;
    return interactionController;
}


- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
    return self.view;
}

pls help me to solve problem...

Payal Maniyar
  • 4,293
  • 3
  • 25
  • 51
Jigar
  • 1,801
  • 1
  • 14
  • 29

1 Answers1

2

Try using this line in your .h file:

@property (strong, nonatomic) UIDocumentInteractionController *documentInteractionController;

And these to your .m file:

self.documentInteractionController= [UIDocumentInteractionController interactionControllerWithURL:url];
//set delegate
[self.documentInteractionController setDelegate:self];
//provide button's frame from where popover will be lauched

[self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
jalpa
  • 36
  • 6