Shared file access for Camera Extension and Cocoa Application

I am currently writing a software product which involves a Camera Extension and a Cocoa application. I would like to share some files between the two components and as of my understanding this should be quite straightforward by putting both applications into the same App Group and then accessing the particular Group Container.

However doing so, does result in both components accessing different locations for the Group Container. I am using the following piece of code to create a new folder inside the container:

let directory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.235ADAK9D5.com.creativetoday.camskool")!
let newDirectory = directory.appendingPathComponent("Mydir")
try? FileManager.default.createDirectory(at: newDirectory, withIntermediateDirectories: false)

If I run this I find that the Cocoa application is going to access the following Location and create the file there:

/Users/<username>/Library/Group Containers/<App Group>/"

Where as the Camera Extension will access the following Location and create the directory there:

/private/var/db/cmiodalassistants/Library/Group Containers/<App Group>/

If I create a file in one directory it does not appear in the other. I tried for both components to access the opposite directory but it results in an permission denied message.

What am I doing wrong?

Accepted Reply

To be clear, we’re talking about Core Media I/O extensions, right?

If so, this:

as of my understanding this should be quite straightforward by putting both applications into the same App Group

won’t work because app groups only work between apps run by the same user. Your main app is being run by some logged in GUI user but your camera extension is not; it’s run by the _cmiodalassistants role account.

I would like to share some files between the two components

What sort of content are we talking about?

Share and Enjoy

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

Replies

To be clear, we’re talking about Core Media I/O extensions, right?

If so, this:

as of my understanding this should be quite straightforward by putting both applications into the same App Group

won’t work because app groups only work between apps run by the same user. Your main app is being run by some logged in GUI user but your camera extension is not; it’s run by the _cmiodalassistants role account.

I would like to share some files between the two components

What sort of content are we talking about?

Share and Enjoy

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

To be clear, we’re talking about Core Media I/O extensions, right?

Correct.

won’t work because app groups only work between apps run by the same user. Your main app is being run by some logged in GUI user but your camera extension is not; it’s run by the _cmiodalassistants role account.

Well that explains everything...

What sort of content are we talking about?

The content is basically video. In our previous (DAL) Plugin we used to have a custom protocol in place which, besides delivering the video, would also hand over some other information like camera states, settings and a few other things. The protocol used to operate by using a shared memory buffer(mmap'ed). The idea was to use the app groups to get shared file access, which now for obvious reasons won't work. Is there another way to achieve this?

Is there another way to achieve this?

It’s tricky. See my response here.

Share and Enjoy

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