objective-c - 如何捕捉 NSWorkspaceDidPerformFileOperationNotification?

标签 objective-c cocoa notifications nsworkspace

我试图在文件操作执行后获得回调,但我无法捕获 NSWorkspaceDidPerformFileOperationNotification 发布。

[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finderDidFileOperation:) name:NSWorkspaceDidPerformFileOperationNotification object:[NSWorkspace sharedWorkspace]];
[[NSWorkspace sharedWorkspace] performFileOperation:fileOp source:source destination:item.fullPath files:objects tag:&tag];

object:nil

也没有用

[[NSWorkspace sharedWorkspace] addObserver:self forKeyPath:NSWorkspaceDidPerformFileOperationNotification options:NSKeyValueObservingOptionNew context:nil];

也是。

我做错了什么?

最佳答案

我认为这里的关键是 NSWorkspace 将通知发布到它的通知中心,而不是全局默认通知中心。来自 the docs :

Before this method returns, it posts an NSWorkspaceDidPerformFileOperationNotification to the NSWorkspace object's notification center.

尝试向该通知中心注册通知,如下所示:

[[[NSWorkspace sharedWorkspace] notificationCenter] 
    addObserver:self 
    selector:@selector(finderDidFileOperation:) 
    name:NSWorkspaceDidPerformFileOperationNotification 
    object:[NSWorkspace sharedWorkspace]];

关于objective-c - 如何捕捉 NSWorkspaceDidPerformFileOperationNotification?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12409661/

相关文章:

ios - 检查 mp3 是否可以在 swift 中播放

iOS - 将 UIMonthYearPicker 与 Interface Builder 结合使用

ios - 使用 UIBezierPath 绘制饼图

objective-c - 初始化WithFrame : method for custom textfield not being called when created in a TableCellView

php - 通知系统(电子邮件、社交媒体)

php - 在 laravel 约会前一小时发送通知

objective-c - 向用户发送当前位置 Xcode

macos - 视网膜问题 (OS X)

objective-c - cocoa sqlite 数据库文件

notifications - 配置 MantisBT 以使用 GMail 发送电子邮件