views:

45

answers:

2

I want to add an icon (icns & ico) to a file within my iPhone app and I'm not quite sure where to start looking! So when this file is viewed in Finder or Windows Explorer it will have a custom icon.

Can anyone point me in the right direction?

+1  A: 

I do not have an answer for Windows Explorer. For MacOS, the custom icon of a file is stored in the resource fork of the file as kIconFamilyType with id kCustomIconResource. The custom icon for a folder is stored in a file named Icon\r (\r meaning mac newline) in the folder. For volumes, the custom icon is in a .VolumeIcon.icns file at the root of the volume. In each case, you must set the kHasCustomIcon Finder flag for the item.

Cocoa does not give you access to the resource fork or the Finder flags. Use FSSetCatalogInfo to set the Finder flags. Use FSCreateResourceFork, AddResource and CloseResFile to add a custom icon family to a file. The same resource fork calls are used for the custom icon file in a folder.

The usual way to set an icon is to either paste it in from the Get Info Finder window, or send the Finder an apple event. You can send apple events from cocoa, but that is no help from an iPhone.

To create a file on an iPhone that has a resource fork, you would probably have to build a zip archive that would create a resource fork when unzipped. You would have to manually build a resource fork wrapper around the icon family data. The resource fork structure is well documented.

It would probably be easier to have a helper application on MacOS.

drawnonward
“It would probably be easier to have a helper application on MacOS.” Or a Quick Look importer, if the goal is to have a preview “icon”. Quick Look importer plug-ins can generate far better previews, not being limited to thumbnail icons.
Peter Hosey
A: 

You can use -setIcon:forFile:options: method on NSWorkspace if you want to change the icon of a file or folder in Mac OS X.

Girish Kolari