"NSTask *capture = [[NSTask alloc] init];
capture.launchPath = @"/usr/sbin/screencapture";
capture.arguments = [NSArray arrayWithObjects:@"-i",@"-c", nil];
[capture setTerminationHandler: ^(NSTask *t) {
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
if ([pboard pasteboardItems].count <= 0) return ;
NSPasteboardItem *pboardItem = [[pboard pasteboardItems] objectAtIndex:0];
NSString *pboardItemType = [[pboard types] objectAtIndex:0];
NSData *imageData = [pboardItem dataForType:pboardItemType];
NSImage *image = [[NSImage alloc] initWithData:imageData];
__weak __typeof(self) weakself= self;
dispatch_async(dispatch_queue_create(0, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
weakself.iconView.image = image;
});
});
}];
[capture launch]; "
这样写报错 screencapture: cannot run two interactive screen captures at a time