簡體   English   中英

取消從UIDocumentInteractionController打開的iOS郵件應用程序,將在iOS7中刪除當前ViewController的視圖

[英]Dismissing iOS mail app opened from UIDocumentInteractionController removes the presenting ViewController's view in iOS7

我已經在我的應用程序中實現了UIDocumentInteractionController ,以顯示打開選項。 在iOS8設備上運行正常,但在iOS7中,當我從選項打開郵件中的PDF時。 當我關閉郵件編輯器時,它會打開郵件編輯器,並且還會從我的視圖(添加到窗口)中刪除一個菜單按鈕。 我整天都在努力解決這個問題,但找不到任何解決方案。 當我用其他選項打開PDF時,沒有問題。 此問題僅與iOS7的郵件編輯器有關。 我知道UIDocumentInterfaceControlleriOS7中有問題。 我在SO上發現了相同的問題,但這是快速瀏覽的預覽選項。

這是我打開選項的代碼

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

任何幫助,將不勝感激。

提前致謝。

   - (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];
    }
}

試試這個,它可能有助於解決您的問題。

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

為此,您可以檢查iOS版本是否小於8,然后像這樣在網絡瀏覽器中打開該pdf文件

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

嘗試這個。 對我來說很好

 @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
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM