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()
}