iOS - Opening files with custom extension from external apps into my app not working

My Swift app should open files with a custom extension, let's say it is 'ext'.

In the info.plist file it's like

<key>UTExportedTypeDeclarations</key>
<array>
	<dict>
		<key>UTTypeDescription</key>
		<string>List of datatype</string>
		<key>UTTypeConformsTo</key>
		<array>
			<string>public.json</string>
			<string>public.database</string>
			<string>public.data</string>
			<string>public.text</string>
			<string>public.content</string>
		</array>
		<key>UTTypeIdentifier</key>
		<string>com.myapp.datatype</string>
		<key>UTTypeTagSpecification</key>
		<dict>
			<key>public.filename-extension</key>
			<array>
				<string>ext</string>
			</array>
			<key>public.mime-type</key>
			<array>
				<string>application/json</string>
			</array>
		</dict>
	</dict>
</array>

the code for handling the opening is in the Application delegate but the app is not called at all.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

     let url=launchOptions?[UIApplication.LaunchOptionsKey.url]

    if ((url) != nil) {

        //importing is implemented here
...
...
    }

    return true
}
...
...

When executing the app on the iOS simulator it happens that

if I select such a file from the Files app it is displayed in the Files app itself, but neither it is opened in my app, nor there is an option to send it to my app diretly.

But the extension seems to be registered because the description (List of datatype) is displayed when the file is opened inside the Files app as JSON text.

What can be done to fix the opening on behalf of other apps, like Files or eMail for example?

Is the provided info.plist snippet correct? Should I to set something else in the project?

Accepted Reply

You export the UTI but you don’t declare that you handle documents of that UTI (CFBundleDocumentTypes). For an example of how to do this, create a new test project from the iOS > Document App template.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • @eskimo Thank you. I created a iOS DocumentApp but I see differences. My app is not a DocumentApp so some items are not available when I try to add them to the info.plist file. So is it possible to find somewhere the missing snippet to have the working feature, so I adapt it to my case and add it to the plist file in my app?

Add a Comment

Replies

You export the UTI but you don’t declare that you handle documents of that UTI (CFBundleDocumentTypes). For an example of how to do this, create a new test project from the iOS > Document App template.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • @eskimo Thank you. I created a iOS DocumentApp but I see differences. My app is not a DocumentApp so some items are not available when I try to add them to the info.plist file. So is it possible to find somewhere the missing snippet to have the working feature, so I adapt it to my case and add it to the plist file in my app?

Add a Comment