Dismissing iOS mail app opened from UIDocumentInteractionController removes the presenting ViewController's view in iOS7
Asked Answered
T

4

35

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.

Trench answered 16/4, 2015 at 10:54 Comment(6)
I think you should use self.window instead of self.view.Erbe
@Erbe window in not accessible from self. I have also tried presenting option menu on application's window.Trench
it can be accessible from self have a look self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];Erbe
NSString *textToShare = @"Los!"; NSURL *myWebsite = [NSURL URLWithString:@"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];Limbo
It removes menu button or removes bottom modal view controller?Culinary
@MayankJain, where you placed a mail app dismiss code?Cudlip
L
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];
    }
}
Ligule answered 9/9, 2015 at 8:47 Comment(2)
check that link it can help youLigule
check the link for more references code.tutsplus.com/tutorials/…Ligule
P
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];
Pinkster answered 27/7, 2015 at 4:36 Comment(1)
I don't want to open preview @angel... I just want to open mail composer from option menu....Trench
P
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];`
Ploughshare answered 17/4, 2017 at 6:58 Comment(0)
D
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
    }
Diary answered 16/11, 2018 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.