Browse Source

fix share - copy on iPad

marinofaggiana 5 years ago
parent
commit
73e770948b
2 changed files with 12 additions and 4 deletions
  1. 1 1
      iOSClient/Share/NCShare.swift
  2. 11 3
      iOSClient/Share/NCShareCommon.swift

+ 1 - 1
iOSClient/Share/NCShare.swift

@@ -188,7 +188,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
     }
     
     func tapCopy(with tableShare: tableShare?, sender: Any) {
-        NCShareCommon.sharedInstance.copyLink(tableShare: tableShare, viewController: self)
+        NCShareCommon.sharedInstance.copyLink(tableShare: tableShare, viewController: self, sender: sender)
     }
     
     func switchCanEdit(with tableShare: tableShare?, switch: Bool, sender: UISwitch) {

+ 11 - 3
iOSClient/Share/NCShareCommon.swift

@@ -173,7 +173,7 @@ class NCShareCommon: NSObject {
         return(calendarView: calendar, viewWindow: viewWindow)
     }
     
-    func copyLink(tableShare: tableShare?, viewController: UIViewController) {
+    func copyLink(tableShare: tableShare?, viewController: UIViewController, sender: Any) {
         
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
         var url: String = ""
@@ -191,8 +191,16 @@ class NCShareCommon: NSObject {
         if let name = URL(string: url), !name.absoluteString.isEmpty {
             let objectsToShare = [name]
             
-            let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
-            viewController.present(activityVC, animated: true, completion: nil)
+            let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
+            
+            if UIDevice.current.userInterfaceIdiom == .pad {
+                if activityViewController.responds(to: #selector(getter: UIViewController.popoverPresentationController)) {
+                    activityViewController.popoverPresentationController?.sourceView = sender as? UIView
+                    activityViewController.popoverPresentationController?.sourceRect = (sender as AnyObject).bounds
+                }
+            }
+            
+            viewController.present(activityViewController, animated: true, completion: nil)
         }
     }
 }