Reputation: 1110
My sandboxed Mac app puts image data as "public.jpeg" data as well as kPasteboardTypeFilePromiseContent onto the pasteboard.
The path used for the promised file is somewhere in the Container folder of my sandboxed app.
This works great to allow dragging to the Finder, but seems to cause problems with other sandboxed apps, that prioritise the promised file data over the image data, e.g. Apple's Pages app.
I cannot find documentation where to write the promised file so other sandboxed apps can access it. Any hints welcome.
NSURL *url = [NSURL fileURLWithPath:self.libraryImage.filePath];
if (url)
{
[pasteboardItem setDataProvider:dataProvider
forTypes:@[(NSString *)kPasteboardTypeFilePromiseContent]];
}
Update:
I got something working by using the NSPasteBoard extension posted here: https://stackoverflow.com/a/18561956/581784
The only thing that's missing is getting the file written at the specific location on the user's desktop, where the drop ended. My current code looks like this:
- (void)pasteboard:(nullable NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSString* /* NSPasteboardType */)type
{
if ([type isEqualToString:(NSString *)kPasteboardTypeFileURLPromise])
{
NSURL *pasteURL = [pasteboard pasteLocation];
if (pasteURL) {
NSString *listingImageUUID = [item stringForType:kGSListingImageUUIDPasteboardType];
GSListingImage *listingImage = (GSListingImage*) [[[GSAppDelegate appDelegate] mainDatabaseContext] objectWithUUID:listingImageUUID ofClass:GSListingImage.class];
NSString *imageName = [listingImage.libraryImage.filePath lastPathComponent];
NSURL *destURL = [pasteURL URLByAppendingPathComponent:imageName];
[[listingImage.libraryImage jpegData] writeToURL:destURL
atomically:YES];
[pasteboard setPasteLocation:destURL];
}
}
}
Upvotes: 1
Views: 725
Reputation: 25246
I cannot find documentation where to write the promised file so other sandboxed apps can access it
This is not how it works. The drop target application first checks if the drag types contain NSFilesPromisePboardType
.
If so the target app sets the location with -[NSDraggingInfo namesOfPromisedFilesDroppedAtDestination:]
or PasteboardSetPasteLocation()
.
Then the target app reads the kPasteboardTypeFileURLPromise
, which triggers the promised file provider app to write it to the location given by the target app.
You need to do this in - (void)pasteboard:(nullable NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSPasteboardType)type;
.
Upvotes: 1