Airdrop custom document type to SwiftUI DocumentGroup app

215 Views Asked by At

I am trying to get a simple SwiftUI iOS custom document app work with Airdrop. The app successfully opens a document when opened from Files or a Mail attachment. However when sending a document of the custom type by Airdrop from my mac, when the app is selected from the Airdrop notification, the app launches but only displays the file browser and the file does not seem to be copied over. No DocumentGroup view is displayed.

If I select Files from the Airdrop menu I can save the file.

I tried this with Apples sample code for DocumentBased apps, and it exhibits exactly the same behavior on my iPhone (iOS 16.0.2). Either this is a bug, or there is some extra secret sauce needed to get a SwiftUI Document app to receive files by Airdrop.

My custom type conforms to public.content, which I understand is required for Airdrop support.

Has anyone managed to get Airdrop reception working with a SwiftUI document app ?

1

There are 1 best solutions below

0
On

I faced the same issue.

What I found out so far:

1. Documents which are received via Airdrop are placed in your "Inbox" folder. This directory is located here:

let docUrl =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

You can add an UIApplicationDelegate and UISceneDelegate to your swiftui application. Here you get a trigger when new files are received via Airdrop.

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)

This function is normally trigged when you open your app with a URL in your browser.

I'm waiting for a integrated solution in the DocumentGroup.

https://developer.apple.com/documentation/swiftui/documentgroup