Skip to content

Sample project illustrating the bug with SwiftUI ShareLink

Notifications You must be signed in to change notification settings

hekuli/apple-bug-sharelink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 28, 2025
8982a2b · Jan 28, 2025

History

1 Commit
Jan 28, 2025
Jan 28, 2025
Jan 28, 2025
Jan 28, 2025
Jan 28, 2025

Repository files navigation

PROBLEM DESCRIPTION

The SwiftUI ShareLink component produces Xcode console errors and inconsistent filenames when using custom file types that conform to Transferable. I have tried a variety of settings and Transferable type conformance, but none of them lead to the desired results.

Dev Environment:

MacOS 15.2 Xcode 16.2 iPhone 16 Pro with iOS 18.2

Expected Behavior

Users should be able to seamlessly share custom file types regardless of the sharing destination. When shared the files should have consitentn filenames and use the registered file extension.

GOAL

I want to register a custom file type for users to share data and later import it into my app. The files are simple opaque JSON, which are not intended to opened/previewed in other applications.

  • I'd like to use SwiftUI's ShareLink to share these in-memory objects on-demand.
  • I'd like sharing to work with all applications provided to users in the iOS share sheet. (e.g. Messages, Mail, Telegram, Signal, WhatsApp, etc)
  • Filnames should match the name propery of the object, and use the registered extension.
  • When receiving a shared file, tapping it should open in the app.

Actual Behavior

Many of the options tried produce this in Xcode's debug console:

Failed to load item provider <NSItemProvider: 0x302a7d570> {types = (
    "com.hekuli.samplefiletype"
)}, falling back to original item provider

In addition to the code below, the following settings have been added to the Info.plist via: the project's Target -> Info tab.

Instructions were followed as outlined here: https://developer.apple.com/documentation/uniformtypeidentifiers/defining-file-and-data-types-for-your-app

Document Types

Name: Some Custom Thing Sample File Types: com.hekuli.samplefiletype Handler Rank: Owner

Exported Type Identifiers

Description: Some Custom Thing Sample File Identifier: com.hekuli.samplefiletype Conforms To: public.data Extension: samplefiletype Mime Types: application/octet-stream

I also tried using various combinations of mime types and public.json.


TEST RESULTS

The sample code below generates the following file names for the selected share targets, regardless of which Transferable protocol is used.

Save to Files -> "Widget.samplefiletype"                                            CORRECT
Messages      -> "Widget.samplefiletype"                                            CORRECT
Mail          -> "Widget.samplefiletype"                                            CORRECT
Signal        -> "Widget.samplefiletype"                                            CORRECT
WhatsApp      -> Doesn't share at all                                               INCORRECT
Telegram      -> "file"                                                             INCORRECT
AirDrop       -> "Some Custom Thing Sample File-4655-924D-1C-0.samplefiletype"      INCORRECT

About

Sample project illustrating the bug with SwiftUI ShareLink

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages