inverse of LSGetApplicationForItem

205 Views Asked by At

I am writing a image viewer application, which I need to set as default application for jpeg/gif files. There is an API LSGetApplicationForItem/Info for getting information on what is the default application. But I am not able to find an API where I can set my application as the default viewer for image files.

Can you please help

2

There are 2 best solutions below

0
On

There's not a public API to do that, as far as I know. Instead, you register, using Info.plist (or the Document Types section of the Info editor in Xcode), that you are a provider of viewing and/or editing for whatever file types you are interested in. This will cause the system to choose your app if there's no other app who can open those file types, and will put you in the running if the user chooses Open With from the context menu when selecting a file in the Finder.

0
On

You want the LSSetDefaultRoleHandlerForContentType function. Pass kUTTypeGIF for GIF, kUTTypeJPEG for JPEG.

Please only do this when the user explicitly tells you to. Otherwise, they will hate you.