未调用 DidEndSendingToApplication

Posted

技术标签:

【中文标题】未调用 DidEndSendingToApplication【英文标题】:DidEndSendingToApplication is not called 【发布时间】:2017-06-30 11:48:55 【问题描述】:

我正在处理使用 UIDocumentInteractionController 发送文件。 我想在发送文件后显示完成警报。 但是,我无法检测到完成事件,因此无法显示警报。 请告诉我如何检测完成事件。

import UIKit

class ViewController: UIViewController, UIDocumentInteractionControllerDelegate 

// Document controller
var dic:UIDocumentInteractionController?    
override func viewDidLoad() 
    super.viewDidLoad()


override func didReceiveMemoryWarning() 
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.



@IBAction func export(_ sender: Any) 
    // url is sample.
    let url = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask, true)[0]).appendingPathComponent("sample.txt")

    dic = UIDocumentInteractionController(url: self.url)
    dic?.delegate = self
    dic?.presentOpenInMenu(from: (self.tabBarController?.tabBar.frame)!, in: self.view, animated: true)


// MARK: UIDocumentInteractionControllerDelegate methods
// Open in menu presented/dismissed on document.  Use to set up any HI underneath.
public func documentInteractionControllerWillPresentOpenInMenu(_ controller: UIDocumentInteractionController) 
    // Called
    print("WillPresentOpenInMenu")


public func documentInteractionControllerDidDismissOpenInMenu(_ controller: UIDocumentInteractionController) 
    // Called
    print("DidDismissOpenInMenu")



// Synchronous.  May be called when inside preview.  Usually followed by app termination.  Can use willBegin... to set annotation.
public func documentInteractionController(_ controller: UIDocumentInteractionController, willBeginSendingToApplication application: String?) 
    // Not Called
    print("willBeginSendingToApplication")



public func documentInteractionController(_ controller: UIDocumentInteractionController, didEndSendingToApplication application: String?) 
    // Not Called
    print("didEndSendingToApplication")

    // I want to display an alert of completion!
    let alert = UIAlertController(title: "Completed", message: "", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
    self.present(alert, animated: true, completion: nil)


【问题讨论】:

【参考方案1】:

遗憾的是,对于显示为覆盖而不是导航到该应用程序(Notes、扩展程序、Airdrop)的应用程序,didEndSendingToApplication 不会被调用。您唯一的选择是在 documentInteractionControllerDidDismissOpenInMenu 上显示警报,但您无法区分正在发送的文件或刚刚关闭的菜单

【讨论】:

以上是关于未调用 DidEndSendingToApplication的主要内容,如果未能解决你的问题,请参考以下文章

numberOfRowsInSection 已调用但 cellForRowAt 未调用

调用 textFieldShouldBeginEditing,未调用 textFieldDidBeginEditing

JQuery:未捕获的类型错误:无法读取未定义的属性“调用”

调用结果未使用

C# Web Api 调用未从 jquery 调用

未调用 cellForRowAtIndexPath 但调用 numberOfRowsInSection