3

I am processing to send a file with UIDocumentInteractionController.
I want to display an alert of completion after sending the file.
However, I can not detect completion events, so I can not display alerts.
Please tell me how to detect completion event.

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 Answer 1

0

Sadly, for the apps that are showed as an overlay instead of navigating to that app (Notes, extensions, Airdrop), didEndSendingToApplication is not called. Your only option would be to show the alert on the documentInteractionControllerDidDismissOpenInMenu but you cannot distinguish between the file being sent or the menu just being closed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.