Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController dismissing current view controller after sharing file

UIActivityViewController dismisses the presenting view controller after sharing files. this is happening in iOS 13+ only. Is there any permanent solution for this? Others apps seem to have this issue too after updating to iOS 13.

   class VC : UIViewController {


   @IBAction func moveFiles(_ sender: UIButton) {

      let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)


    alertController.addAction(UIAlertAction(title: "Move", style: .default, handler: { action in

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


   if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad) {
   activityController.popoverPresentationController?.sourceRect = sender.frame
    activityController.popoverPresentationController?.sourceView = sender.superview
    }
   self.present(activityController, animated: true, completion: nil)


    }))




           }


     }
like image 820
Mariela Avatar asked Oct 28 '22 04:10

Mariela


1 Answers

Here is the work around for your issue.

let tempController = TransparentViewController()
tempController.modalPresentationStyle = .overFullScreen

activityViewController.completionWithItemsHandler = { [weak tempController] _, _, _, _ in
  if let presentingViewController = tempController?.presentingViewController {
    presentingViewController.dismiss(animated: false, completion: nil)
  } else {
    tempController?.dismiss(animated: false, completion: nil)
  }
}

present(tempController, animated: true) { [weak tempController] in
    tempController?.present(activityViewController, animated: true, completion: nil)
}
like image 83
Amrit Trivedi Avatar answered Oct 31 '22 09:10

Amrit Trivedi