Search code examples
cocoadrag-and-dropphotonsdragginginfonsdraggingdestination

How do I implement drag-and-drop from Photos to my Cocoa app with full quality?


In my drag destination view (NSView subclass), I have implemented:

override func performDragOperation(_ draggingInfo: NSDraggingInfo) -> Bool {

    // check for Photos promises
    var gotPromised = false
    draggingInfo.enumerateDraggingItems(options: [], for: self, classes: [NSFilePromiseReceiver.self], searchOptions: [:], using: {(draggingItem, idx, stop) in
        let filePromiseReceiver = draggingItem.item
        print("got a file promise receiver: \(filePromiseReceiver)")
        gotPromised = true
        // Use filePromiseReceiver here for your task.
    })
    return gotPromised
}

When I run this and drag something over from Photos.app, I get this warning:

Photos warning

How do I fix my drag destination to not have this warning? I would like to get full-quality photos into my app.


Solution

  • Well. Figured it out myself after some investigation. You need to do multiple things (register for correct types, enumerate the items correctly etc), and the warning is not there if you just implement the promise receiving completely and correctly. Apple has provided an example project which implements everything correctly.