简体   繁体   English

用户清空垃圾箱时收到通知?

[英]Notification when user empties trash?

How would my cocoa app receive a notification when the user empties their trash. 当用户清空垃圾桶时,我的可可应用如何收到通知。 This is what I have so far: 这是我到目前为止的内容:

 NSNotificationCenter *notCenter = [[NSWorkspace sharedWorkspace]
                                       notificationCenter];
    AppDelegate *mainController = [[AppDelegate alloc] init];

    [notCenter addObserver:mainController
                  selector:@selector(handleTrashEmpty)
                      name:NSWorkspaceRecycleOperation object:nil];

But when nothing shows up when the user empties their trash. 但是,当用户清空垃圾箱时却什么也没有出现。 Any ideas why this code is not working? 有什么想法为什么此代码不起作用?

1st way: 第一种方式:

You can use UKKQueue to watch file change (empty thrash) notifications: 您可以使用UKKQueue来监视文件更改(空刷新)通知:

http://www.cocoadev.com/index.pl?UKKQueue http://www.cocoadev.com/index.pl?UKKQueue

2nd way: 第二种方式:

Keep on checking with a timer if the [folderList count]==0, means trash is emptied. 如果[folderList count] == 0,则继续使用计时器检查,这表示垃圾已清空。

NSError *error=nil;
NSString *path=[NSHomeDirectory() stringByAppendingPathComponent:@".Trash"];
NSArray *folderList=[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];

3rd way: 第三种方式:

watch ~/.Trash, "com.apple.carbon.core.DirectoryNotification" is posted when the trash is emptied. 观看〜/ .Trash,清空垃圾箱后会发布“ com.apple.carbon.core.DirectoryNotification”。

NSWorkspaceRecycleOperation is not a notification at all but a file operation constant passed to performFileOperation:source:destination:files:tag: NSWorkspaceRecycleOperation根本不是通知,而是传递给performFileOperation:source:destination:files:tag的文件操作常量:


you use the FSEvents api to monitor /.Trashes. 您使用FSEvents api监视/.Trash。 Here's some sample code: http://subversion.assembla.com/svn/quotamonitormenu/QuotaMonitorMenu/branches/QuotaMonitorMenuFaculty/StatusItemController.m 以下是一些示例代码: http : //subversion.assembla.com/svn/quotamonitormenu/QuotaMonitorMenu/branches/QuotaMonitorMenuFaculty/StatusItemController.m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测用户何时从通知中心清除通知 - Detect when a user clears notification from the notification center 如何在区域更改用户时获取通知? - How to get Notification when region Changes of the user? 仅在用户单击时处理本地通知 - Handle local notification only when the user clicks on it 当用户属性更改时,将推送通知发送到特定的用户ID - Send push notification to specific user ID when properties for user changed 当应用程序移至垃圾箱或在Mac中被垃圾箱丢弃时如何获得通知? - How to get notified when an application moved to trash or an application trashed in mac? 如何在用户点按推送通知时禁用打开应用 - How to disable opening app when user tap push notification 如何检测用户何时清除您的应用通知 - How to detect when user clears your app's notification iOS - 用户在“设置”中手动启用“推送通知”时的委托方法 - iOS - Delegate method when user turns on Push Notification manually in Settings 当用户点击通知IOS7时,导航到特定的视图控制器 - Navigate to particular view controller when user tap the notification IOS7 iOS:当应用程序处于前台状态时,如何让用户忽略远程通知? - iOS: how to let the user ignore a remote notification when app is in foreground?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM