UIActivityViewController 在共享文件后关闭当前视图控制器

Mar*_*ela 5 iphone ipad ios swift

UIActivityViewController 在共享文件后关闭呈现视图控制器。这仅在 iOS 13+ 中发生。有没有永久的解决方案?更新到 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)


    }))




           }


     }
Run Code Online (Sandbox Code Playgroud)

Amr*_*edi 3

这是解决您的问题的方法。

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)
}
Run Code Online (Sandbox Code Playgroud)