Hi dts,
thanks for chiming in.
In the debugger of the HostApp I see this error: Type "com.myapp.shareInput" was expected to be exported in the Info.plist of Host.app, but it was imported instead. Library: UniformTypeIdentifiers | Subsystem: com.apple.runtime-issues | Category: Type Declaration Issues
You're seeing the error because "com.fesh.shareInput" wasn't added in the app's info.plist
But it was added in the Host.app Info.plist - as imported, not exported.
I wrote in my first posting:
I definitely want to define and export both ShareInput and ShareResult as UTExportedTypeDeclarations in my extension, and all 3rd-party apps (like this demo HostApp) using my extension need to import them.
We expect more 3rd party apps to use our extension, which IS the source of truth for these types. So it doesn't make sense for my sample demo Host.app to export them.
However, I will add them just for debugging, to check whether that's the problem.
Side Question 3: In the HostApp, can I use ShareLink() to present the Share-sheet and receive the result struct
You could use ShareLink to present the share interface. For the imported content type, Transferable. handles the CodableRepresentation handles the conversion of the model type to and from binary data.
Both my types are really simple structs, input contains 3 strings and output contains 4. For the simplicity of this demo project I only used 1 string each, just to demonstrate the data passing as Transferable. I could easily pack this data myself as JSON in a single TEXT blob since this seems to work best in my experience up to now, but I really want to use Transferable with CodableRepresentation and understand what is needed to make this work.
However in some cases you would need to implement the closure that instantiates the item inother to convert the binary data to a type that your app is aware of
My data only exists in memory and not as file, thus a file representation doesn't make sense for me.
When you define a uniform type identifier, remember you need to declare it to be either an imported or exported type:
• An exported type declaration is declared and owned by your application. For example, the Codable schema of ShareInput is an exported content type com.fesh.shareInput. Your application is the source of truth about given type, and it is also the primary handler of files with the corresponding file extension.
Actually, my extension is the source of truth about both structs. I didn't define file extensions because the data is only in memory. It doesn't make sense to share that data via Mail, Messenger or AirDrop with another device. The only usecase is that both the 3rd party HostApp and my ContainingApp are installed on the same iPhone, and the HostApp uses my SharingExtension to communicate with my ContainingApp without switching context.
An imported type declaration is owned by some other app, that may not be present on the device when your app is installed.
We want to create a demo to show 3rd party developers how to use our SharingExtension. I understand that the 3rd party HostApp thus needs to import the types to be able to make Transferable work.
In my demo project:
I imported the types both in the Host.App as well as in the Containing.App, and exported them in the ShareExtension.
I tried to export them from the Containing.App instead (and removed the declaration from the Extension's Info.plist) - but that lead to this error:
Type "com.fesh.shareInput" was expected to be declared and exported in the Info.plist of ShareExtension.appex, but it was not found.
Thus I added the export declaration back to the ShareExtension's Info.plist, and that error vanished.
Now I am exporting both types, both from the ContainingApp as well as from it's ShareExtension. Is that really OK?