Supporting AdaptiveImageGlyph copying & pasting

I am currently running iOS 18 Beta 3 and am working on enabling users to paste (and copy) custom emojis (AdaptiveImageGlyph, such as Memoji, Stickers, and soon GenMoji) into a text field.

I am looking for the UTI for AdaptiveImageGlyph—something similar to "public.adaptive-image-glyph". Does anyone know if such a UTI exists?

Here’s my situation: When typing AdaptiveImageGlyph using the System keyboard, everything functions correctly. However, if I copy some text containing AdaptiveImageGlyph from the Notes app and paste it into my playground app, it only pastes the text. The reverse is also true. In fact, if I copy some AdaptiveImageGlyph from the playground app and paste it, it only pasts the text.

Interestingly, copying AdaptiveImageGlyph from the Notes app and pasting it into iMessage works flawlessly, and vice versa. I am trying to achieve the same seamless functionality in my app.

Given that this feature works in iMessage and Notes, I am inclined to believe the issue might be on my side, though I recognize these are system apps and not third-party.

Example Code:

import SwiftUI
import UIKit

struct AdaptiveImageGlyphTextView: UIViewRepresentable {
    class Coordinator: NSObject, UITextViewDelegate {
        var parent: AdaptiveImageGlyphTextView
        
        init(parent: AdaptiveImageGlyphTextView) {
            self.parent = parent
        }
        
        func textViewDidChange(_ textView: UITextView) {
            parent.text = textView.text
        }
        
        func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
            // Handle insertion of adaptive image glyphs here if needed
            return true
        }
    }

    @Binding var text: String
    
    func makeCoordinator() -> Coordinator {
        Coordinator(parent: self)
    }
    
    func makeUIView(context: Context) -> UITextView {
        let textView = UITextView()
        textView.delegate = context.coordinator
        textView.supportsAdaptiveImageGlyph = true
        textView.isEditable = true
        textView.isSelectable = true
        textView.font = UIFont.systemFont(ofSize: 17)
        
        // Enable paste with NSAdaptiveImageGlyphs
        textView.pasteConfiguration = UIPasteConfiguration(acceptableTypeIdentifiers: [
            "public.text",
            "public.image",
            "public.adaptive-image-glyph" // Replace with the correct UTI if different
        ])
        
        return textView
    }
    
    func updateUIView(_ uiView: UITextView, context: Context) {
        if uiView.text != text {
            uiView.text = text
        }
    }
}

struct ContentView: View {
    @State private var text: String = ""
    
    var body: some View {
        AdaptiveImageGlyphTextView(text: $text)
            .frame(height: 200)
            .padding()
    }
}
#Preview {
    ContentView()
}

EDIT: what you're looking for is UTType.heic. Finally got Xcode beta up & running and was able to look at NSAdaptiveImageGlyph.contentType.identifier from the debugger and see that it's "public.heic" (UTType.heic)

I was looking at this: https://developer.apple.com/documentation/uikit/nsadaptiveimageglyph/4395169-contenttype.

NSAdaptiveImageGlyph will have a class var contentType which is a UTType, which you should take a look at. It's a convenience class provided by apple to reason about the type of data (no need to hard code "public.image", instead you can use UTType.image). AFAICT, there's no new UTType for adaptiveImageGlyph / Genmoji, etc. that's been added yet.

Maybe you could try UTType.heic The documentation states:

Adaptive images are compatible with the HEIC format, but include extra metadata about the supported resolutions and sizes.

This might unblock you in the meantime. However it sounds like NSAdaptiveImageGlyph will essentially be an HEIC with some additional data, so it may still get its own UTType later on.

How did you create NSAdaptiveImageGlyph objects without Genmoji by the way? Also, I tried constructing a NSAdaptiveImageGlyph object from HEIC content in the pasteboard but was not able to do so. It's unclear as to wether Apple will be extending HEIC with their additional metadata or if HEIC will just be a way to access the raw image data only from an NSAdaptiveImageGlyph. I believe it will be the latter.

Supporting AdaptiveImageGlyph copying & pasting
 
 
Q