I used to be able to accept promised files from Mail.app that were dropped into my collection view, but it stopped working in 10.13. From the release notes, it seems that I should be using the NSFilePromiseReceiver, so I tried that, but it isn't working out for me. I do read the NSFilePromiseReceiver object form the pasteboard, but the filename is empty, ... "receivePromisedFilesAtDestination" is called, and the file actually does transfer into the promised location, but the callback takes over 30 seconds and is then called with an error.
I register for the drop in awakeFromNib:
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[NSFilePromiseReceiver readableDraggedTypes]];
[array addObject: NSURLPboardType];
[self.filesCollection registerForDraggedTypes: array];
In CollectionView's delegate:
- (BOOL)collectionView:(NSCollectionView *)collectionView acceptDrop:(id <NSDraggingInfo>)draggingInfo indexPath:(NSIndexPath *)indexPath dropOperation:(NSCollectionViewDropOperation)dropOperation {
if([[pboard types] containsObject:NSFilesPromisePboardType]) {
self.savedPromisedFiles = [pboard readObjectsForClasses: @[[NSFilePromiseReceiver class]] options:nil];
NSString *directory = [[[SharedSettingController sharedSettings] applicationSupportPath] stringByAppendingPathComponent: kAttachmentsDirectoryLocal];
NSURL *dropLocation = [NSURL fileURLWithPath:directory];
for (NSFilePromiseReceiver *promise in self.savedPromisedFiles) {
NSLog (@"promise.fileNames = %@, type = %@", promise.fileNames, promise.fileTypes);
[promise receivePromisedFilesAtDestination:dropLocation options:@{} operationQueue: operationQueue reader:^(NSURL * _Nonnull fileURL, NSError * _Nullable errorOrNil) {
if (errorOrNil) {
NSLog(@"file promise error = %@", errorOrNil);
} else {
NSLog(@"file promise url = %@", fileURL);
}
}];
}
}
}
Any ideas what am I doing wrong here, or what I should look into?
Thanks.