Some NSFilePresenter protocol methods not called

I've implemented the NSFilePresenter protocol in a Mac app (Catalina 10.15.3 Xcode 10.15.3) to watch a directory.


Most protocol methods get called correctly, but some don't get called at all. For some there are (cumbersome) alternatives, but if, for example a file is immediately deleted in Finder using option+command+del, the NSFilePresenter delegate never receives any callback. Is there a workaround to trigger the callbacks?


final class FileController: NSObject, NSFilePresenter {

     ...

     init() {
           presentedItemURL = // Some directory
           NSFileCoordinator.addFilePresenter(self)
     }

     func accommodatePresentedItemDeletion(completionHandler: @escaping (Error?) -> Void) {
          // Never gets called
          completionHandler(nil)
     }

     func presentedSubitemDidAppear(at url: URL) {
          // Never gets called
     }

     func presentedSubitemDidChange(at url: URL) {
          // Does get called
     }
}

Replies

I am encountering same issue.

I am encountering same issue.

Unless someone else chimes in, I’m going to recommend that you open a DTS tech support incident so that I, or one of my colleagues, can look into this in more detail.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Have you implemented presentedSubitemAtURL: didMoveToURL: ?

My guess is that deleting it actually moves it to trash, and that is what will be reported to you via the didMove... method. That is what I see on iOS when I delete a file using the Files app.

Now this raises the question of what we're supposed to do in that case. If the user renames a file that I am presenting, or moves it to a different folder, then I update anywhere that is showing the filename and continue to display the file. (Right?) But if the user deletes the file from the files app, I think they will be surprised if my app continues to display it with the new filename ".Trash/name". Do I have to specifically detect filenames that contain the magic component ".Trash"?