Universal Type Identifiers Tutorial for iOS: Importing and Exporting App Data | raywenderlich.com

In this tutorial, you’ll learn how to export and import app data to and from your iOS app, as well as create custom file types and extensions.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/8413525-universal-type-identifiers-tutorial-for-ios-importing-and-exporting-app-data

I have run into a weird issue. All was running well, but when I played around with the settings below, when I drag the prioritized tasklist on to the simulator, rather than starting TaskList it opens Files and asks me where I want to save the file. Nothing else has changed. I’m wondering, is it possible that I’ve typed it in correctly (it seems to be correct to me) but it hasn’t accessed the proper internal properties (assuming that UITypeTagSpecification is not just a made up label)?

Additional Exported UTI properties:

UITypeTagSpecification/Dictionary
public.filename-extension/Array
item 0/String/rwtl
item 1/String/RWTL

I’ve discovered my error. I had UITypeTag…

It should be UTTypeTag…

Great lesson btw. Thank you.

I have one more question, if anyone is reading this. Dragging a file, or clicking on it - if open files in place is set - starts the app up. How can you get it to open on the screen that you want? Would this be set in the openURLContexts method, or somewhere else?

@ehabamer Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hello @religionofpeas,
My apologies for not getting back to you much sooner :]

The idea of setting up the URL is for the iOS to know which app to open when you setup the URL scheme, what the OS actually does is pass the whole URL to your app as it opens.

In the article at this part https://www.raywenderlich.com/8413525-universal-type-identifiers-tutorial-for-ios-importing-and-exporting-app-data#toc-anchor-009 whether you are using scenes or not in your app, when the app received the path for the file, what you should do is check the file and directly open the screen you want programmatically.
There is no way to tell the OS to open a specific screen work you, that should be handled from within your app directly.

Let me know if that answered you or if you have any further details you would like to know :]

No worries, ehabamer, and thanks for your reply. I have sorted out getting the screen that I want, using this code:

if let tabBarController = self.window!.rootViewController as? UITabBarController {
tabBarController.selectedIndex = 1
}

I’m having difficulty though in using SceneDelegate. I don’t want my app to run in the background, but when it isn’t running in the background openURLContexts does not get called.

I came across the below discussion in stackOverFlow about calling openURLContexts manually, but the code they use isn’t working for me - at least not in the simulator. Nothing gets called in the AppDelegate either. Any ideas on to how to call it?

Obviously links aren’t allowed. Here it is without the https:

//stackoverflow.com/questions/58973143/method-scene-openurlcontexts-is-not-called

1 Like

Thanks for the tutorial! It was helpful.

However, I’m having an issue with the non-scene version (I haven’t tired the scene version since I’m not using scenes). The openURL function is being called in response to sharing a file from the Files.app to my app, but the URL I receive doesn’t point to an actual file. It seems like a valid URL and the file name it references is correct, but I used FIleManager.fileExists() on the URL and it says it doesn’t exist. I output the directory contents of the URL (tmp directory for my app) to the log and there is nothing in it.

What’s going on?