ios复制到剪贴板

时间:2022-12-07 19:36:26

 UIPasteboard 这个就是剪贴板

 UIPasteboard * pastboard = [UIPasteboard generalPasteboard];

        pastboard.string = self.scanResult;

        

        [LCAlert toastShow:@"扫描结果已复制到剪贴板"];

 

常用方法:

/*通过名称获取粘贴板并且移除*/
+ (void)removePasteboardWithName:(NSString *)pasteboardName;
/*从粘贴板中获取数据,pasteboardType是自定义的,说明app可以处理哪种类型的数据*/
- (nullable NSData *)dataForPasteboardType:(NSString *)pasteboardType;
/*data类型的数据放在粘贴板中,pasteboardType同上*/
- (void)setData:(NSData *)data forPasteboardType:(NSString *)pasteboardType;
/*从粘贴板中取出data*/
- (nullable NSData *)dataForPasteboardType:(NSString *)pasteboardType;