Obj-C:FSEvent 在每次启动应用程序时报告相同的事件

发布于 2024-09-06 04:41:13 字数 383 浏览 4 评论 0原文

我设置了一个运行良好的 FSEvent,但每次启动应用程序时它都会报告相同的事件。

例如:

我的 FSEvent 监视器目录是:

Test/

...并且有三个文件:

test1, test2, test3

但是,在我删除 FSEvent 目录中的 test1 后,它一直告诉我 test1 已被删除每次运行程序时都会删除,而不是删除后一次。

我清理了上下文中的所有托管对象并删除了整个目录,但该事件不断被报告。

我应该怎么做才能让它只在删除后立即告诉我,然后再也不会告诉我?

多谢!

I setup a FSEvent that runs well but it keeps reporting the same event each time I launch the app.

Ex:

My FSEvent monitor directory is:

Test/

...and there are three files:

test1, test2, test3

However, after I deleted test1 in my FSEvent Directory, it keeps telling me that test1 has been deleted every time I run the program instead of just the one time after the deletion.

I cleaned all managedObjects in my context and deleted the whole directory but the event keeps being reported.

What should I do such that it only tells me right after the deletion and then never again?

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言月老 2024-09-13 04:41:13

文件系统事件在启动之间保持不变。它们由文件系统本身而不是应用程序跟踪。这就是为什么您每次启动时都会看到该事件。

我相信您必须调用FSEventsPurgeEventsForDeviceUpToEventId或类似的方法来清除事件。

对此持保留态度。我没怎么摆弄它。

编辑:

来自 文件系统事件编程指南

要处理持久事件,您的
应用程序应定期存储
它处理的最后一个事件 ID。然后,
当它需要回去看看什么时候
文件已经改变,只需要
查看之后发生的事件
最后已知的事件。获取所有事件
自从过去的某个特定事件以来,
您在sinceWhen 中传递事件ID
FSEventStreamCreate 的参数或
FSEventStreamCreateRelativeToDevice。]
[在每台设备的基础上,您还可以
轻松使用时间戳来确定
包括哪些事件。为此,
你必须先打电话
FSEventsGetLastEventIdForDeviceBeforeTime
获取sinceWhen之后的最后一个事件ID
论证
FSEventStreamCreateRelativeToDevice。

我认为要记住的重要一点是,文件系统事件实际上并未存储,甚至与正在观察它们的应用程序无关。它们独立于文件系统本身中的应用程序而存在。在实践中,可以设置多个不同的应用程序来观察同一事件。

File system event are persistent between launches. They are tracked by the file system itself, not the app. That is why you keep seeing the event every time you launch.

I believe you have to call FSEventsPurgeEventsForDeviceUpToEventId or the like to clear the events.

Take that with a grain of salt. I haven't fiddled with it much.

Edit:

From File System Events Programming Guide:

To work with persistent events, your
application should regularly store the
last event ID that it processes. Then,
when it needs to go back and see what
files have changed, it only needs to
look at events that occurred after the
last known event. To obtain all events
since a particular event in the past,
you pass the event ID in the sinceWhen
argument to FSEventStreamCreate or
FSEventStreamCreateRelativeToDevice.]
[On a per-device basis, you can also
easily use a timestamp to determine
which events to include. To do this,
you must first call
FSEventsGetLastEventIdForDeviceBeforeTime
to obtain the last event ID sinceWhen
argument to
FSEventStreamCreateRelativeToDevice.

I think the important thing to remember is that the file system events are not actually stored or even related to app that is observing them. They exist independently of the app in the file system itself. In practice, several different apps could be set to observe the same event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文