UIActivityViewControllerCompletionHandler How to?

后端 未结 5 1760
予麋鹿
予麋鹿 2021-02-02 10:05

I am trying to use the UIActivityViewControllerCompletionHandler , but i dont quite get how..

I want to detect when the user finishes or dismisses this

5条回答
  •  感情败类
    2021-02-02 10:55

    Swift 5:

    func showShareOf(url: URL, title: String) {
        let shareItems: [Any] = ["\(title)\n", url]
        let activityVC = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
        activityVC.completionWithItemsHandler = doneSharingHandler
        self.present(activityVC, animated: true, completion: nil)
    }
    
    @objc func doneSharingHandler(activityType: UIActivity.ActivityType?, completed: Bool, _ returnedItems: [Any]?, error: Error?) {
        if (!completed) { return }
        // If here, log which activity occurred
        print("Shared activity: \(activityType)")
    }
    

提交回复
热议问题