34

I have implemented UIDocumentInteractionController in my app for showing open in options. It's working fine on iOS8 devices, but in iOS7 when I open my PDF in the mail from options. It opens mail composer when I dismiss the mail composer it also removes a menu button from my view (which is added to the window). I spent my whole day struggling with this issue but could not find any solution. When I open my PDF in other options, there is no issue. The issue is only with mail composer with iOS7. I know UIDocumentInterfaceController has issue with iOS7. I found the same issue on SO but this is with preview option of a quick look.

Here is my code to open options

[self.docInteractionController presentOptionsMenuFromRect:self.view.frame
                                                   inView:self.view
                                                 animated:YES];

Any help on this will be appreciated.

Thanks in advance.

tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
  • I think you should use self.window instead of self.view. – IOSDev Apr 16 '15 at 14:54
  • @IOSDev window in not accessible from self. I have also tried presenting option menu on application's window. – Mayank Jain Apr 17 '15 at 05:45
  • it can be accessible from self have a look self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; – IOSDev Apr 18 '15 at 07:08
  • NSString *textToShare = @"Los!"; NSURL *myWebsite = [NSURL URLWithString:@"http://www.a.com/"]; UIImage *image = [UIImage imageNamed:@"index.jpg"]; NSArray *objectsToShare = @[textToShare, myWebsite, image]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; NSArray *excludeActivities = @[UIActivityTypeAirDrop, ]; activityVC.excludedActivityTypes = excludeActivities; [self presentViewController:activityVC animated:YES completion:nil]; – ashForIos May 11 '15 at 10:25
  • It removes menu button or removes bottom modal view controller? – Vitalii Gozhenko Jun 04 '15 at 07:16
  • @MayankJain, where you placed a mail app dismiss code? – Ganpat Jun 26 '19 at 11:47

4 Answers4

1
   - (IBAction)previewDocument:(id)sender {
    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"sample" withExtension:@"pdf"];

    if (URL) {
        // Initialize Document Interaction Controller
        self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];

        // Configure Document Interaction Controller
        [self.documentInteractionController setDelegate:self];

        // Preview PDF
        [self.documentInteractionController presentPreviewAnimated:YES];
    }
}
Kamalkumar.E
  • 254
  • 2
  • 11
0

Try this one, it may help to solve your problem.

NSURL* url = //...Your URL //[NSURL fileURLWithPath:path];
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController presentPreviewAnimated:YES];
VRAwesome
  • 4,721
  • 5
  • 27
  • 52
0

for this you can check the iOS version if it's < 8 then open that pdf file in web browser like this

    UIWebView *webview = [[UIWebView alloc] init];
    [self.view addSubview:webview];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"pdfFileName" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [webview loadRequest:request];`
Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
Rogger98
  • 1
  • 1
0

Try this. Its working fine for me

 @IBAction func btnPresentAction(_ sender: UIButton) {

        let fileURL = Bundle.main.path(forResource: "backgroundPerson", ofType: "png")

        let urlI = URL(fileURLWithPath: fileURL!)

        let documentController = UIDocumentInteractionController.init(url: urlI)

        documentController.delegate = self

//        documentController.presentOptionsMenu(from: self.view.frame, in: self.view, animated: true)
        documentController.presentPreview(animated: true)

//        self.present(documentController, animated: true, completion: nil)

    }

    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return self
    }

    func documentInteractionControllerViewForPreview(_ controller: UIDocumentInteractionController) -> UIView? {
        return self.view
    }

    func documentInteractionControllerRectForPreview(_ controller: UIDocumentInteractionController) -> CGRect {
        return self.view.frame
    }
vijay
  • 1,475
  • 2
  • 16
  • 26