2017-02-12 16 views
3

我正在處理髮送一個文件與UIDocumentInteractionController。
我想在發送文件後顯示完成警報。
但是,我無法檢測到完成事件,所以無法顯示警報。
請告訴我如何檢測完成事件。DidEndSendingToApplication不叫

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

回答

0

不幸的是,對於那些表現出作爲覆蓋,而不是導航到該應用程序(注,擴展空投)的應用程序,didEndSendingToApplication不被調用。您唯一的選擇是在documentInteractionControllerDidDismissOpenInMenu上顯示警報,但您無法區分正在發送的文件或正在關閉的菜單