Override Mac application file associations via CFBundleDocumentTypes in info.plist

I am developing a Mac application that saves and downloads files of a unique type. The type is correctly declared in info.plist under CFBundleDocumentTypes, which is specified as LSHandlerRank: Owner and CFBundleTypeRole: Editor. I am releasing a new version of my application, and I would like for users who already had a previous version of my application to install a new version on their computer, but keep the old version, the new version automatically uses file association for this type from the old version of the application. But the default behavior of the OS, apparently, is to provide the earliest installed application associated with the file type with a permanent owner, unless the user changes it manually. I know duti command line toolcan make changes to the association, and the com.apple.LaunchServices.plist system file can be edited, but this doesn't seem like the best or most reliable way to do this programmatically from an application. Is there any “right” / Apple-sanctioned way to do what I want?

+4
source share
1 answer

The official, Apple-approved app method for installing the default app for a file type should probably use the function provided by it LSSetDefaultRoleHandlerForContentType. This function sets the values ​​stored in LaunchServices.

Here is the limited official documentation on how to use this API in Objective-C and Swift.

, Info.plist, . , API.

+3

All Articles