I can't understand how to perform actions after UIActivityViewController
is called.
For example when I save image with the following code:
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let activity = UIActivityViewController(activityItems: [image], applicationActivities: nil)
presentViewController(activity, animated: true, completion: nil)
User receives new window with ability to save image somewhere. After the image was successfully saved I want to perform some action (for example jump to root view controller). But I can't figure out how to track that this UIActivityViewController
was closed. If I write code after this block, nothing happens, as I understand, because this code is implemented in the activity VC, not in original VC.
I thought that viewWillDisappear
will help me, but it tracks the original VC, from where I called activity VC and I can't figure out how can I track activity VC. At the same time, even if I had ability to track this event, there is a question still remains: how can I differ successful save from the cancelation?
You can use a completionHadler
, in this case:
activity.completionWithItemsHandler = { activity, success, items, error in
print("activity: \(activity), success: \(success), items: \(items), error: \(error)")
}
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