NSOutlineView drag and drop with security scoped URL fails when using NSPasteboardItem

Viewed 79

I've an NSOutlineView that contains URL's as items. These URL's are security scoped and I want them to be able to be dragged to other applications.

When I just return the URL (item) in func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? everything works fine. But for local drag and drop (row reordering) I need additional info, so I create an NSPasteboardItem() to hold the data:

func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? {
    let pasteboardItem=NSPasteboardItem()
    let itemURL = item as! NSURL

    //Write the absolute URL for d'n'd to other apps or windows
    pasteboardItem.setPropertyList(itemURL.pasteboardPropertyList(forType: .fileURL)!, forType: .fileURL)

    //Write data for local d'n'd.
    pasteboardItem.setPropertyList(<data>, forType: dragDropImageURLType)

    return pasteboardItem
}

When I use this code I get the following error, and the drop fails:

[general] Sandbox extension data required immediately for flavor public.file-url, but failed to obtain.

How can I make sure the write of the URL to the NSPasteboardItem works the same way as directly returning the URL?

0 Answers
Related