Dima Paliychuk
Dima Paliychuk

Reputation: 303

Check application to sharing text with UIActivityViewController in Swift

For sharing message I use UIActivityViewController.

Code:

let textShare = [ "text" ]
let activityViewController = UIActivityViewController(activityItems: textShare , applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self?.view
present(activityViewController, animated: true, completion: nil)

But I need to change text for different application, so my question is:

How I can check what application(for example mail or skype), user choose for sharing text?

enter image description hereenter image description here

Upvotes: 1

Views: 691

Answers (1)

user10249172
user10249172

Reputation:

Use completionWithItemsHandler of UIActivityViewController to telled which application selected by user shared the content.

activityVC.completionWithItemsHandler = {(activityType: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in
    if !completed {
        // User canceled 
        return
    }
    // User completed activity
}

self.present(activityVC, animated: true, completion: nil)

Upvotes: 2

Related Questions