Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController UIActivityViewControllerCompletionWithItemsHandler

  • List item

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) 
like image 909
Custom_Software Avatar asked Dec 13 '14 01:12

Custom_Software


Video Answer


1 Answers

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   } 
like image 67
Ian Avatar answered Sep 23 '22 04:09

Ian