Portrait

I2H3

Notes from work as an app developer for iPhones, iPads and Macs.

RSS Icon GitHub Mastodon

File Provider Domain Connection to File Provider Domain

We need file provider extension processes to talk to each other. What first appeared to be prevented by sandbox on iOS works with a different API.

Earlier I wrote on how to successfully fetch the file provider services based on user-visible URL on iOS. Well, that became a problem again when I wanted to connect to a file provider service from another file provider extension process and not just the container app. We have the odd requirement that one file provider domain process may create other file provider domains based on its received data. Those new domains and their processes must be provisioned with user information somehow, of course, via XPC.

But NSFileProviderManager throws an error due to lack of permission accessing the URL. Strangely, this happens on iOS only. On macOS this works fine. Security scoped URL access did not help this time.

I stumbled over a more recent API again which I have seen months ago already but forgot meanwhile. The NSFileProviderManager.getService(named:for:completionHandler:) (asynchronously known as service(named:for:)) not just overcomes the problem but simplifies service lookup implementation overall. So this is the way to go.

No more user visible URLs, service retrieval and filtering for the right service with the right name. This was even more cumbersome a few years ago without asynchronous methods but completion handlers.