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

398 views Asked by At

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?

0

There are 0 answers