Uidropinteractiondelegate Performdrop Not Called

UIDropInteractionDelegate performDrop not called?

I just tested your code and all methods are getting called. It must be a glitch.

Troubleshooting steps:

Delete app -> Restart the simulator -> Clean build folder -> Rebuild -> Run. You can also try running in different simulator first to save time.

Receive JSON file in DropInteraction in iOS app running in Mac Catalyst

You don't need URL, because drop item already has item provider for JSON data, so it is just needed to extract that data from NSItemProvider and decode.

Here is fixed parts (tested with Xcode 12.1)

func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
session.items.forEach { item in
guard item.itemProvider.hasItemConformingToTypeIdentifier(SentimentViewController.JSONTypeIdentifier) else { return }
item.itemProvider.loadDataRepresentation(forTypeIdentifier: SentimentViewController.JSONTypeIdentifier) { data, error in
if let data = data {
self.importJSONData(from: data)
}
}
}
}

private func importJSONData(from data: Data) {
print("Decode JSON from \(data.description).")
}


Related Topics



Leave a reply



Submit