Swift 5 - The below function covers most of the UIActivityViewController properties. It worked for me and thought so it might be helpful for you guys as well.
func performShareAction() {
let itemsToShare : [Any] = ["Hello World"]
let activityView = UIActivityViewController(activityItems: itemsToShare, applicationActivities: nil)
// Apps that you want to exclude sharing the items
let excludedActivityTypes : [UIActivity.ActivityType] = [
.addToReadingList,
.assignToContact,
.copyToPasteboard,
.mail,
.markupAsPDF,
.message,
.openInIBooks,
.postToFacebook,
.postToFlickr,
.postToTencentWeibo,
.postToTwitter,
.postToVimeo,
.postToWeibo,
.print,
.saveToCameraRoll
]
activityView.excludedActivityTypes = excludedActivityTypes
self.present(activityView, animated: true, completion: nil)
activityView.completionWithItemsHandler = { activityType, completed, items, error in
// Event Cancelled
if !completed {
print("Content Sharing was cancelled.")
return
}
// Content Shared on particular activity
print("Shared on activity type: \(String(describing: activityType?.rawValue))")
// Detect app on which the items are shared
if let type = activityType {
switch type {
case .addToReadingList: print("Added To Reading List"); break
case .airDrop: print("AirDropped to Other Device"); break
case .assignToContact: print("Assigned To Contact"); break
case .copyToPasteboard: print("Copied To Pasteboard"); break
case .mail: print("Mailed"); break
case .markupAsPDF: print("Marked-Up As PDF"); break
case .message: print("Messaged"); break
case .openInIBooks: print("Opened In iBooks"); break
case .postToFacebook: print("Posted To Facebook"); break
case .postToFlickr: print("Posted To Flickr"); break
case .postToTencentWeibo: print("Posted To Tencent Weibo"); break
case .postToTwitter: print("Posted To Twitter"); break
case .postToVimeo: print("Posted To Vimeo"); break
case .postToWeibo: print("Posted To Weibo"); break
case .print: print("Printed"); break
case .saveToCameraRoll: print("Saved To Camera Roll"); break
default: print("Shared with new app"); break
}
}
}
}