Drag & Drop on iOS14 doesn't work

I am experimenting with drag & drop to later include it in my app.

I come up with a working solution which allows to drag an item from a VStack and it works just fine on iOS 13.5.

Unfortunately, the same code doesn't work on iOS 14.0 simulator (Xcode 12 beta 3).

iOS 13.5: On Item drop, first loadData is called and then object is called and providers in onDrop contains an item

iOS 14.0: On Item drop no functions are called and providers in onDrop is empty

I am not able to figure out if iOS 14.0 requires additional code or this is an issue of iOS 14.

Any idea?

Code Block
struct ContentView: View {
    @ObservedObject var model = Model()
    var body: some View {
        HStack {
            Spacer()
            VStack {
                ForEach(model.items, id: \.name) { item in
                    ItemView(item: item)
                }
            }
            Spacer()
            DropView().environmentObject(model)
        }
    }
}
struct ItemView: View {
    var item: Item
    var body: some View {
        Text(item.name)
            .onDrag({
                    NSItemProvider(object: self.item)
                })
    }
}
struct DropView: View {
    @EnvironmentObject var model: Model
    var body: some View {
        Text("Drop Here")
            .onDrop(of: [Item.typeIdentifier], isTargeted: nil) { providers, position in
                print("providers \(providers) position \(position)")
                guard let provider = providers.first(where: { provider in provider.hasItemConformingToTypeIdentifier(Item.typeIdentifier) })
                else {
                    return false
                }
                provider.loadObject(ofClass: Item.self) { reading, _ in
                    guard let item = reading as? Item else {
                        return
                    }
                    DispatchQueue.main.async {
                        self.model.items.removeAll(where: { a in a.name == item.name })
                    }
                }
                return true
            }
    }
}
class Model: ObservableObject {
    @Published var items = [
        Item(name: "Item 1"),
        Item(name: "Item 2"),
        Item(name: "Item 3"),
        Item(name: "Item 4"),
    ]
}
class Item: NSObject {
    public static let typeIdentifier = "dnd.item"
    var name: String
    init(name: String) {
        self.name = name
        super.init()
    }
}


I'm having the same problem too. Drop doesn't call call performDrop() in the Drop Delegate. Like you I'm using SwiftUI. I'll post back if I figure it out.

Are you seeing in the console the message "PBItemCollectionServicer connection disconnected."?
I am also having this issue, with the same console message as @texasexile. My code:

Code Block Swift
struct ContentView: View {
@State private var names: [NSString] = ["John","Hunter","Mark","Tom","Jeremy","Bill","Frank"]
@State private var isTargeted: Bool = false
let string = NSString("Test")
var body: some View {
GeometryReader { g in
VStack(alignment: .leading) {
ForEach(names, id: \.self) { name in
HStack {
Text(name as String)
.padding()
Spacer()
}
.border(Color.black)
.onDrag {
NSItemProvider(item: name, typeIdentifier: UTType.modelName.identifier)
}
}
}
.onDrop(of: [UTType.modelName], delegate: Delegate(list: $names))
.padding()
}
}
}
struct Delegate: DropDelegate {
@Binding var list: [NSString]
func performDrop(info: DropInfo) -> Bool {
guard info.hasItemsConforming(to: [UTType.modelName]) else {
return false
}
let providers = info.itemProviders(for: [UTType.modelName])
if let provider = providers.first {
provider.loadItem(forTypeIdentifier: UTType.modelName.identifier) { (name: NSSecureCoding?, error: Error?) in
if let name = name as? NSString {
list.append(name)
/* This part isn't finished */
}
}
}
return true
}
}
extension UTType {
static let modelName: UTType = UTType("model.name")!
}

I am using NSString in this example, but I'm only doing this to test with a type conforming to NSSecureCoding since I was having issues in a more complicated sample.
Hello there,

I'm obtaining the same result using Objective-C UICollectionView: "PBItemCollectionServicer connection disconnected." is shown.

Any update?
The same problem in my app, any of you guys has already found solution?
Having the same issue. SwiftUI. The implementation works nicely in iOS 13.x, but the drops don't work in iOS 14.
Drag & Drop on iOS14 doesn't work
 
 
Q