How do I set returnedItems in the CompletionWithItemsHandler for UIActivityViewController

I have a UIActivityViewController. I want to be able to pass back values from the UIActivity to the CompletionWithItemsHandler using returnedItems. In the UIActivity, I'm using a UIViewController to prompt the user for parameters. How to I set values so they are returned in returnedItems?

Thanks!

Replies

Could you show your code ? And explain what is precisely the problem ?

API is:

CompletionWithItemsHandler = (UIActivity.ActivityType?, Bool, [Any]?, Error?) -> Void

So you call as:

       activityVC.completionWithItemsHandler = { (activity, success, modifiedItems, error) in
            print("activity: \(activity), success: \(success), items: \(modifiedItems), error: \(error)")
      }

If you want to reuse returned items, just have a var for it:

        var returnedItems: [Any]? = nil
        activityVC.completionWithItemsHandler = { (activity, success, modifiedItems, error) in
            returnedItems = modifiedItems
        }

Hope that answers your question.

  • Thanks, but I can see how to get the values out of the completion handler. What I don't understand is how to get values from a UIActivity into what gets returned in the completion handler. I only see 'activityDidFinish' and that's just the bool (which I think is what gets returned as success).

Add a Comment