Re: Drag and Drop from Photos
Re: Drag and Drop from Photos
- Subject: Re: Drag and Drop from Photos
- From: Graham Cox <email@hidden>
- Date: Sun, 26 Apr 2015 13:25:23 +1000
Thanks Ken, that’s helpful.
One problem I’m having is that my app is still largely using legacy approaches to receiving drags based on PBoard types. I’m taking this opportunity to bring it up to date.
So, I’m now registering my view to receive public.data and public.content. It’s no longer rejecting the drag immediately, and I see the following on the pasteboard:
drag content: (
"dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu",
"Apple files promise pasteboard type",
"com.apple.pasteboard.promised-file-content-type",
"com.apple.pasteboard.promised-file-url",
"dyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3k",
NSPromiseContentsPboardType,
"com.apple.UXCollectionView.draggingitem",
"com.apple.UXCollectionView.sourcepointer",
"dyn.ah62d4rv4gu8ywyc2nbu1g7dfqm10c6xekr1067dwr70g23pw",
IPXPasteboardController,
“com.apple.PhotoPrintProduct.photoUUID”
)
So it looks as if the URL of the image(s) that I’m dragging are promised. I’m not sure what constant, if any, that corresponds to in the API. According to the header notes:
> The recommended approach for reading URLs is as follows:
>
> NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; // get pasteboard
> NSArray *classArray = [NSArray arrayWithObject:[NSURL class]]; // types of objects you are looking for
> NSArray *arrayOfURLs = [pasteboard readObjectsForClasses:classArray options:nil]; // read objects of those classes
>
> To read only file URLs, use the NSPasteboardURLReadingFileURLsOnlyKey option in a dictionary provided to -readObjectsForClasses:options:.
> NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSPasteboardURLReadingFileURLsOnlyKey];
>
> To read only URLs with particular content types, use the NSPasteboardURLReadingContentsConformToTypesKey option in a dictionary provided to -readObjectsForClasses:options:. In the sample below, only URLs whose content types are images will be returned.
> NSDictionary *options = [NSDictionary dictionaryWithObject:[NSImage imageTypes] forKey:NSPasteboardURLReadingContentsConformToTypesKey];
>
> To read only file URLs with particular content types, combine the two options.
>
However, when I do this, I get an empty array for the returnd URLs. This is true even if I just ask for all URLs unfiltered (nil options dictionary). The headers don’t have any info about what do to if the URL is only promised - I had thought that from the receiver’s point of view that was irrelevant and transparent, and the promise would be fulfilled when the receiver asked for the URLs, but that’s clearly not happening. Of course I’m using the dragging pasteboard in my case, not the general one.
Any ideas what I’m not doing that I should be?
—Graham
> On 26 Apr 2015, at 12:10 pm, Ken Thomases <email@hidden> wrote:
>
> On Apr 25, 2015, at 8:37 PM, Graham Cox <email@hidden> wrote:
>
>> I’d like a user to be able to directly drag and drop an image from Photos into my app. Currently the drag is rejected, though I’m registering for all of the usual types - NSURLs, Filenames, Images, etc. How can I find out what drag flavours I need to support to enable this? The Finder accepts drags from Photos.
>
> You can use the ClipboardViewer sample app to look at the drag pasteboard after a drag attempt.
> <https://developer.apple.com/library/mac/samplecode/ClipboardViewer/Introduction/Intro.html>
>
> You could also register to receive public.data and public.content, to accept almost anything and then log the actual types in a drag from Photos.
>
> Regards,
> Ken
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden