Can you dynamically assign CFBundleDocumentTypes to your Cocoa application?
Asked Answered
G

1

13

Can you dynamically assign CFBundleDocumentTypes to your Cocoa application? Meaning during run time can I assign more extensions for my app to handle.

Currently I set some extensions for my app to handle using CFBundleDocumentTypes in the Info.plist, but I would like to do this through code while the application is executing (during run time). Basically can I make Launch Services aware of new extensions without modifying the Info.plist file.

Thanks.

Grano answered 17/12, 2011 at 1:56 Comment(0)
M
9

At the moment, there’s no public API1 for an application to dynamically (un)register document types with Launch Services during runtime.

Open Emu faces this very problem. Users are able to selectively download/install emulators, which are bundles whose Info.plist files define document types. Upon installing an emulator, the types defined in the bundle need to be part of the types as defined in the application Info.plist. Open Emu rewrites the application Info.plist in order to do so — see -updateInfoPlist in OEGameDocumentController.

Note that overwriting the bundle Info.plist is a violation of Mac App Store’s policy.

We have filed radars asking for runtime (un)registration of document types. I suggest you file another one, too, which should be closed as a duplicate of #2526726. Even if it’s a duplicate, it’s important to file it anyway so that Apple have an estimate of the number of people that need this feature.

1It might be possible via SPI, though. When I was looking into this, I stumbled upon _LSRegisterItemFromItemInfo() in Launch Services.

Micrography answered 22/12, 2011 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.