美文网首页
Mac OS 开发 为什么这样写不行

Mac OS 开发 为什么这样写不行

作者: 心语风尚 | 来源:发表于2018-08-17 17:55 被阅读16次

"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

  回复

相关文章

网友评论

      本文标题:Mac OS 开发 为什么这样写不行

      本文链接:https://www.haomeiwen.com/subject/sfptiftx.html