iOS 13 UIActivityViewController automatically present previous VC after image saving

I'm trying to implement “Save image to Library” function and then return back to the current view controller, but on a new iOS 13 it dismisses back to the view controller that presented the current one:


PHPhotoLibrary.requestAuthorization({(_ status: PHAuthorizationStatus) -> Void in })

let shareItems: Array = [newImg,"Hello"] as [Any]

let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)

if UIDevice.current.userInterfaceIdiom == .pad {
  activityController.popoverPresentationController?.sourceView = saveButton
}

present(activityController, animated: true)

Having same Issue in iOS 15.4.1: UIActivityViewController when save image is tapped it will save image as well as close the modal with parent view controller. 

Solution: Use custom ActivityViewController:

class CustomActivityViewController: UIActivityViewController {

   override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
        // super.dismiss(animated: true, completion: completion)
        // Disabling this dismiss will not close your parent view controller
    }
}
iOS 13 UIActivityViewController automatically present previous VC after image saving
 
 
Q