关闭从 UIDocumentInteractionController 打开的 iOS 邮件应用程序会删除 iOS7 中呈现的 ViewController 的视图

Posted

技术标签:

【中文标题】关闭从 UIDocumentInteractionController 打开的 iOS 邮件应用程序会删除 iOS7 中呈现的 ViewController 的视图【英文标题】:Dismissing iOS mail app opened from UIDocumentInteractionController removes the presenting ViewController's view in iOS7 【发布时间】:2015-04-16 10:54:07 【问题描述】:

我在我的应用中实现了 UIDocumentInteractionController 以显示打开选项。它在 ios8 设备上运行良好,但在 iOS7 中,当我从选项的邮件中打开我的 PDF 时。当我关闭邮件编写器时,它会打开邮件编写器,它还会从我的视图中删除一个菜单按钮(添加到窗口中)。我整天都在努力解决这个问题,但找不到任何解决方案。当我在其他选项中打开我的 PDF 时,没有问题。问题仅与 iOS7 的邮件编写器有关。我知道 UIDocumentInterfaceController 在 iOS7 上存在问题。 I found the same issue on SO 但这是带有快速查看的预览选项。

这是我打开选项的代码

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

对此的任何帮助将不胜感激。

提前致谢。

【问题讨论】:

我认为你应该使用 self.window 而不是 self.view。 @IOSDev 窗口无法从自身访问。我也尝试在应用程序的窗口上显示选项菜单。 可以从self访问看看 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 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]; 移除菜单按钮还是移除底部模态视图控制器? 【参考方案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];
    

【讨论】:

检查链接是否对您有帮助 查看链接以获取更多参考资料code.tutsplus.com/tutorials/…【参考方案2】:

试试这个,它可能有助于解决您的问题。

NSURL* url = //...Your URL //[NSURL fileURLWithPath:path];
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController presentPreviewAnimated:YES];

【讨论】:

我不想打开预览@angel...我只想从选项菜单中打开邮件编辑器...【参考方案3】:

为此,您可以检查 iOS 版本是否为

    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];`

【讨论】:

【参考方案4】:

试试这个。它对我来说很好用

 @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
    

【讨论】:

以上是关于关闭从 UIDocumentInteractionController 打开的 iOS 邮件应用程序会删除 iOS7 中呈现的 ViewController 的视图的主要内容,如果未能解决你的问题,请参考以下文章

从活动结果意图按下后退按钮时应用程序关闭[关闭]

如何从同一片段中的关闭按钮关闭片段?

从角度组件关闭电子应用程序

从 NotificationContentExtention 关闭 IOS 通知

从关闭消息中检索代码/原因

无法从 'char[]' 转换为 'string[]' [关闭]