Using Swift for an app that runs in iOS 8, I need to write a completion handler for the UIActivityViewController
to capture the results of which "share" method a user selected.
This is a snippet of the code I have so far. My question is how to I set the avc.completionWithItemsHandler
? I'm sure it's simple, but I don't see it.
var activityItems = NSMutableArray() activityItems.addObject("Email or text for 'share' goes here") var avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil) avc.setValue("Subject for Email", forKey: "Subject") avc.completionWithItemsHandler = //Here is where I dont know what to do. self.navigationController?.presentViewController(avc, animated: true, completion: nil)
The completionWithItemsHandler typealias:
typealias UIActivityViewControllerCompletionWithItemsHandler = (String?, Bool, [AnyObject]?, NSError?) -> Void
Note: the previous code block is not to be used in your project, it just shows the type of closure needed (docs).
So those are the parameters that are passed into the completion handler for you to do with as you will, so the completion handler would look like this:
avc.completionWithItemsHandler = { activity, success, items, error in }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With