Sharing text file with Airdrop is opening in Files rather than in my SwiftUI app

116 views Asked by At

I have a SwiftUI app and I'm trying to share a string from my app to my app on another device. I am using sharelink to share the link using airdrop.

On the receiving device, the text opens directly in the files app and not in my app. I can't find too much information on how to make this work properly.

My approach is below: to send:

ShareLink(item: "The string I want to share.") {
    Image(systemName: "square.and.arrow.up")
        .imageScale(.large)
}

this is sent as a .txt file

to receive:

struct ExampleApp: App {
        
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some SwiftUI.Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    print("url")
                    // Handle the incoming file URL
                }
        }
    }
}

my info.plist:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>My App Data</string>
        <key>LSHandlerRank</key>
        <string>Default</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.text</string>
        </array>
    </dict>
</array>
<key>UIFileSharingEnabled</key>
<true/>

When I send via airdrop to another device with my app on it, the file just opens in files and shows the string. .onOpenURL is not called in receiving app. Am I missing any steps here?

0

There are 0 answers