3

ファイル操作の実行後にコールバックを取得しようとしましたが、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];

オブジェクト:なし

また、動作しませんでした

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

それも。

私は何を間違っていますか?

4

1 に答える 1

3

NSWorkspaceここで重要なのは、グローバルなデフォルトの通知センターではなく、通知センターに通知を投稿することだと思います。ドキュメントから:

このメソッドが戻る前に、NSWorkspaceDidPerformFileOperationNotification を NSWorkspace オブジェクトの通知センターに投稿します。

代わりに、次のように、その通知センターに通知を登録してみてください。

[[[NSWorkspace sharedWorkspace] notificationCenter] 
    addObserver:self 
    selector:@selector(finderDidFileOperation:) 
    name:NSWorkspaceDidPerformFileOperationNotification 
    object:[NSWorkspace sharedWorkspace]];
于 2012-09-13T15:34:53.047 に答える