NSFilePresenter -presentedSubitemDidAppearAtURL: method never gets called

为君一笑 提交于 2019-12-04 17:45:29

问题


I have an object which conforms to NSFilePresenter protocol that represents my document-based application document package. When a new file is created inside the package, either programmatically using NSFileManager with proper NSFileCoordination methods or via Finder i only got -presentedSubitemDidChangeAtURL: event, but not seeming so obvious in this case -presentedSubitemDidAppearAtURL:.

Is this an expected behavior or i am doing something wrong?

The comments on -presentedSubitemDidAppearAtURL: in NSFilePresenter state it clear:

Be notified that a file or directory contained by the directory has been added. If this method is not implemented but -presentedItemDidChange is, and the directory is actually a file package, then the file coordination machinery will invoke -presentedItemDidChange instead.


回答1:


After struggling with this exact issue for quite a while, I opened a technical support issue with Apple. Their response was that this is a bug, and the only thing we can do right now is to do everything through -presentedSubitemDidChangeAtURL:.

I would encourage anyone encountering this issue to file a bug (https://bugreport.apple.com) to encourage Apple to get this problem fixed as soon as possible.




回答2:


https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSFilePresenter_protocol/

Your presenter objects are not notified about changes made directly using low-level read and write calls to the file. Only changes that go through a file coordinator result in notifications.



来源:https://stackoverflow.com/questions/12389726/nsfilepresenter-presentedsubitemdidappearaturl-method-never-gets-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!