如何更新共享按钮编码以在 iOS 13 上工作

How to update share button coding to work on iOS 13

我的分享按钮代码适用于 iOS13 以下的所有版本,如何修改代码以适用于 iOS13 IPad 和 [=17] =]?

   class CatseyeViewController: BaseViewController{
        
        @IBOutlet weak var sliderImage: UIImageView!
        
        
        @IBAction func share(_ sender: UIButton) {
        
          let activityController = UIActivityViewController(activityItems: 
[self.sliderImage.image as Any], applicationActivities: nil)
                           
    self.present(activityController, animated:true, completion: nil)
         
    if let popOver = activityController.popoverPresentationController {
        popOver.sourceView = self.view
                             
              }
                       
                      
                   }
                
        }

为了更新共享 sheet 以在 iOS 13 上工作,创建一个 IF/ELSE 语句首先检测 iOS 13 与所有其他版本。

 class CatseyeViewController: BaseViewController{

 @IBOutlet weak var sliderImage: UIImageView!
 
@IBAction func share(_ sender: UIButton) {
        
        let version = OperatingSystemVersion(majorVersion: 13, minorVersion: 0, patchVersion: 0)
                  if ProcessInfo.processInfo.isOperatingSystemAtLeast(version) {
                     /* runNewCode()*/
        let items = [self.sliderImage.image]
               let ac = UIActivityViewController(activityItems: items as [Any], applicationActivities: nil)
           UIApplication.shared.windows.first?.rootViewController?.present(ac, animated: true, completion: nil)
                    
                    if UIDevice.current.userInterfaceIdiom == .pad {
                               ac.popoverPresentationController?.sourceView = UIApplication.shared.windows.first
                              ac.popoverPresentationController?.sourceRect = CGRect(
                                   x: UIScreen.main.bounds.width / 2.1,
                                   y: UIScreen.main.bounds.height / 2.3,
                                   width: 200, height: 200)
                           }         
        }
        else
                  {
        /* runOriginalCode() that works for earlier IOS*/
        
        let activityController = UIActivityViewController(activityItems: [self.sliderImage.image as Any], applicationActivities: nil)
        
        self.present(activityController, animated:true, completion: nil)
        if let popOver = activityController.popoverPresentationController {
            popOver.sourceView = self.view
         
        }
      
    
        }//end of else statement
    }//end of share function
}//end of controller