我试图在文件操作执行后获得回调,但我无法捕获 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/