我需要将已删除的数据复制到自定义路径。有了图像,它的工作正常。这是代码:
- (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];
}];
}
这段代码很好地保存了丢失的图像到MYPATH ...但是,如果我想保存非图像文件,但是有些自定义格式&#34; mybinarydata.dat&#34;?我知道我必须使用loadObjectsOfClass:[NSData self]并保存&#34; objectAtIndex:0&#34;直? - 但我现在正在工作((