1 Reply
      Latest reply on Nov 1, 2019 2:18 AM by eskimo
      SyamalaDutt Level 1 Level 1 (0 points)

        From below description https://developer.apple.com/documentation/bundleresources/information_property_list/nsfileproviderdomainusagedescription?changes=_2_1__8

         

        The user implicitly grants your app access to a file managed by a file provider when selecting the file in an Open or Save panel, dragging it onto your app, or opening it in Finder. Your app can access that file right away and any time in the future

         

        In my application i select a file from open Panel and create a duplicate using CopyItem API try fileMgr.copyItem(atPath: uploadfilePath, toPath: newTempFilePath) .. I see catalina user consent coming, when i click on dont allow , i am not entering catch block and API is successful. When i checked read permissions

        FileManager.default.isReadableFile(atPath: SelectedPath) , it returns true.

        • Re: Selecting a file from open panel still throws user consent alert
          eskimo Apple Staff Apple Staff (12,265 points)

          It would help if you were more specific about the code you wrote, the directory you chose the file from, and the error you got.  Failing that, I wrote a small test project to exercise this case.  The code is pasted in at the end.

          When I ran this on 10.15 and choose a file from the desktop, it’s able to successfully copy it.  I ran this outside of Xcode, just to make sure the debugger wasn’t affecting things.  In Console I saw two log entries:

          default
          02:15:27.629730-0700
          Test125301
          QQQ will copy /Users/quinn/Desktop/tmp.txt to /var/folders/ks/l3tlbq5x5gj6ycrwg6sv81jc0000gp/T/Test125301-300323C6-2DEE-4D19-8662-31FA68AD0343/tmp.txt
          
          default
          02:15:27.729106-0700
          Test125301
          QQQ did copy /Users/quinn/Desktop/tmp.txt to /var/folders/ks/l3tlbq5x5gj6ycrwg6sv81jc0000gp/T/Test125301-300323C6-2DEE-4D19-8662-31FA68AD0343/tmp.txt

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"


          @IBAction func testAction(_ sender: Any) {
              let panel = NSOpenPanel()
              panel.beginSheetModal(for: self.window) { response in
                  if response == .OK {
                      let sourceURL = panel.url!
                      let fm = FileManager.default
                      let tmpDir = fm.temporaryDirectory
                      let targetDir = tmpDir.appendingPathComponent("Test125301-\(UUID().uuidString)")
                      let targetURL = targetDir.appendingPathComponent(sourceURL.lastPathComponent)
                      do {
                          NSLog("QQQ will copy %@ to %@", sourceURL.path, targetURL.path)
                          try fm.createDirectory(at: targetDir, withIntermediateDirectories: false, attributes: nil)
                          try fm.copyItem(at: sourceURL, to: targetURL)
                          NSLog("QQQ did copy %@ to %@", sourceURL.path, targetURL.path)
                      } catch {
                          NSLog("QQQ something failed, error: %@", "\(error)")
                      }
                  }
              }
          }