I need to copy dropped data to my custom path. With images it's working fine. Here is the code:
- (UIDropProposal *)dropInteraction:(UIDropInteraction *)interaction sessionDidUpdate:(id<UIDropSession>)session {
UIDropProposal *proposal = [[UIDropProposal alloc] initWithDropOperation: UIDropOperationCopy];
return proposal;
}
- (BOOL)dropInteraction:(UIDropInteraction *)interaction canHandleSession:(id<UIDropSession>)session {
return [session canLoadObjectsOfClass:[UIImage self]];
}
- (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session {
[session loadObjectsOfClass:[UIImage self] completion:^(NSArray *images) {
UIImage *image=(UIImage*)[images objectAtIndex:0];
[UIImagePNGRepresentation(image) writeToFile:"<MYPATH>" atomically:YES];
}];
}
This code nicely save dropped image to MYPATH... But what, if i want to save non-image file, but some custom format "mybinarydata.dat"? I understand that I must use loadObjectsOfClass:[NSData self] and save "objectAtIndex:0" directly? - but i's now working(((