0

I have a SwiftUI View conforming to DropDelegate and working correctly in order to receive images from other apps in macOS and iPadOS, but the behavior in both operative systems are quite different:

struct ContentView: View { 
    var body: some View {
        MyView { ... }
            .onDrop(of: [.fileURL, .image], delegate: self)
    }
}

And the DropDelegate implementation is:

extension ContentView: DropDelegate { 
   func performDrop(info: DropInfo) -> Bool {
      // Debug implementation
      if info.hasItemsConforming(to: [.image]) { 
         print("CONTAINS AN IMAGE")
      } else if info.hasItemsConforming(to: [.fileURL]) { 
         print("CONTAINS AN URL")
      }
   }
}

If I'm on macOS the output is CONTAINS AN URL, and if I'm on iPadOS the output is CONTAINS AN IMAGE.

The problem is that I need to access to some metadata (like the creationDate) of the source URL, and I cannot access to the creationDate if the output is an UIImage. How can I access to the source URL on iPadOS/iOS via DropDelegate? Or... How can I get the creationDate of an UIImage provided by DropDelegate?

Xcode 13 | macOS 12 | iPadOS 15 | Swift 5.5 | SwiftUI 3.0

AlbertUI
  • 1,409
  • 9
  • 26
  • 1
    Remove the `else`, does the iPad trigger with both image an URL? `DropInfo` can have multiple items, and this not only means that it can receive multiple items, it also means that an item may be represented in multiple ways. – EmilioPelaez Sep 05 '21 at 11:38
  • @EmilioPelaez Yes, I tried removing `else` and `[.image]` is only triggered on iPadOS, and `[.fileURL]` is only triggered on macOS. Also tried with `[.url]` – AlbertUI Sep 05 '21 at 11:42
  • Have you been able to solve this issue? macOS seems not to work with types like .image or .audio or .video – Daniel Feb 05 '22 at 18:20
  • Nope :(, on iPadOS you still get the data, not the url. – AlbertUI Feb 06 '22 at 19:02

0 Answers0