When your app has some unique file to handle and you feel creating custom file extension or adding the custom file extension created by another developer that suits your needs then follow this article to make it possible.
Before going straight away to the procedure/steps, let us understand the Uniform Type Identifiers in iOS development.
Uniform Type Identifiers
Uniform Type Identifiers carries identity of your documents or files across the system. UTI tells system what apps can handle that particular document. For example when you try to open image, you can see various supported applications under ‘Open With’ in finder.
In the same way if you want to introduce a new file type or use the custom file type created by another developer, You need to tell the system first that your app gonna handle that file type.
So the steps are either import(use UTI crated by another developer) or export(owner of UTI) UTI and then add that document type to your application. When you are exporting, you are the owner of UTI and on the other case, you are using one made by another developer.
Exporting Uniform Type Identifier
In this case, You are the owner of UTI and your app is introducing a new file extension or document type to system.
- Go to Target -> Info tab in XCode.
2. Click on Exported Type Identifiers
3. Fill the Description and extension for UTI. You no need to enter ‘.’ specifically in extension field.
4. Name your Identifier.
5. Add some of standard UTIs if applicable in ‘confirms to’ field. If you are handling some image kind of thing then add public.img, public.data etc.. Most of common UTIs confirms to
6. Add icons and reference url if applicable.
You need to be careful while giving identifier. Reverse DNS must be possible with your identifier. So choose something unique like com.<BundleName>.extesnion. Also don’t ever use any apple reserved UTIs like com.example.*, com.apple.* etc..
Importing Uniform Type Identifier
The process and fields are exactly same. Just add the details of UTI created by another developer. Remember when you are importing some UTI, you are not the owner of it.
Adding Document Type
After either exporting or importing the UTI, you need to tell the system your app is handling. You are doing that here.
- Click on Document types in same tab.
2. Give it a name.
3. Add the identifier like com.<Bundle>.extension in Types.
4. Set Handler Rank to ‘Owner’ if you are exporting or ‘Alternate’ if you are importing.
That’s it you can go head and implement document handling logic in code. Your extension is now a UTI. Check out Apple Developer talk for live demo
NOTE : There are some standard UTIs like public.image which you don’t need to import explicitly. These are already available in ‘/System/Library/CoreServices/CoreTypes.bundle’.
Thanks for Reading…))