Search code examples
iosmacosmac-catalyst

Mac Catalyst - Dragging to an inactive window


An iPad app that accepts UIImage objects as dragging items has been built for macOS via Catalyst in Xcode 11b6.

When I drag images from Finder or Photos I am finding that my app must first be placed in the foreground to accept the drag.

This works.

  • Foreground my app.
  • Drag image into app. Drop is accepted.

This doesn't work.

  • Background my app.
  • Drag image into app. No drop handlers are triggered, drop is NOT accepted.

Expected behaviour is that content can be dragged into an inactive window like any Cocoa app.

I am implementing UIDropInteractionDelegate.

extension MyViewController: UIDropInteractionDelegate {

  func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
    return session.canLoadObjects(ofClass: UIImage.self)
  }

  func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
    //only want external app sessions
    if session.localDragSession == nil {
      return UIDropProposal(operation: .copy)
    }
    return UIDropProposal(operation: .cancel)
  }

}

Is this a Catalyst beta quirk or is some extra UIWindow/UIScene magic required?


Solution

  • It seems like this was a Catalina bug that was fixed in one of the latest betas. I'm running Beta 7 and this issue no longer exists.