Search code examples
macosfileprovider-extension

File Provider UI extension on macOS


I'm asking this because the documentation is totally contradicting to itself on multiple occasions:

  • Extensions overview page (https://developer.apple.com/app-extensions/) claims it's not supported.
  • At the same time, on FileProviderUI docs page (https://developer.apple.com/documentation/fileproviderui) macOS is listed among another platforms and docs kinda generally suggest it is supported.
  • At the same time, "add new target" dialog in xcode is missing "File Provider UI Extension" template under macOS.
  • At the same time, it's can be easily be done by creating an iOS extension, then swapping SDK to macOS and UIKit APIs to their AppKit counterparts. This way, FileProviderUI actions DO appear in Finder.

Problem is, after clicking the action, UI never appears and here's what i see in Console:

default pkd Waiting on thread <private> until Launch Services database seeding is complete.
default Finder  [d <private>] <PKHost:0x600000c38cc0> Beginning discovery for flags: 1024, point: (null)
default Finder  [d <private>] <PKHost:0x600000c38cc0> Completed discovery. Final # of matches: 0
error   Finder  nil extension for provider ID (<private>), error: (null)
error   Finder  Action with identifier (<private>) did finish with error (Error Domain=FPUIActionViewControllerErrorDomain Code=1000).
error   Finder  FP Custom action sheet finished with error Error Domain=FPUIActionViewControllerErrorDomain Code=1000 "(null)"
default pkd [d <private>] Final plugin count: 0

This is totally confusing, so if anyone has been able to use FileProviderUI on macOS - please share your success story.


Solution

  • Okay, here's my success story:

    • The error in question was due to missing entitlements file for FileProviderUI extension
    • Next, apparently, unlike iOS, macOS FileProviderUI extension does not support NSExtensionMainStoryboard Info.plist key. Using NSExtensionPrincipalClass worked like a charm.
    • Also, don't forget to load view for principal class (e.g. by having corresponding .xib)
    • And keep in mind that on macOS prepareForActionWithIdentifier:itemIdentifiers: and prepareForError: are called before viewDidLoad thus outlets would be nil at that moment (on iOS it's vice versa)