At WWDC 23 a new feature named NameDrop was introduced. This feature makes it possible to share content from one device to another by simple placing them close to each other. To support this there are a few things we have to do.

First of all our struct/class has to conform to Transferable. The Transferable protocol explains to the system how your content is shared.

One way to share recipes in Ambre is via URL, the conformance looks like this:

public class ShareableWebRecipe: Transferable {
    let recipe: Recipe

    public init(recipe: Recipe) {
        self.recipe = recipe
    }

    static public var transferRepresentation: some TransferRepresentation {
        ProxyRepresentation { shareableRecipe in
            try await Share.share(recipe: shareableRecipe.recipe, isAddedToGallery: false, container: CoreDataContainer.shared)
        }
    }
}

Once this is in place we can share a recipe using ShareLink.

ShareLink(
    item: ShareableWebRecipe(recipe: recipe),
    preview: SharePreview(recipe.safeName, image: recipe.getImage()),
    label: {
        Label("Share", systemImage: "square.and.arrow.up")
    })

If we tap the ShareLink button the following share sheet is presented:

Share sheet screenshot

In this view we first tap AirDrop followed to placing our device close to another unlocked device. The NameDrop animation occurs and the content is transferred.

Ambre has support for Universal Linking, which means the received URL will open up Ambre and present the shared recipe. Here’s what it looks like: