Why is NSMetadataQueryDidUpdateNotification called multiple times in a row?

To track file changes in my iCloud container, I signed up for

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processiCloudUpdates:) name:NSMetadataQueryDidUpdateNotification object:nil]; 

Ideally, whenever I get a message that updates have been made, I would like to open each of my UIDocs and check if the settings have been changed. It would be nice if NSMetadataQueryDidUpdateNotification was called only once. However, it starts several times (I didnโ€™t forget removeObserver , etc. And I executed several instances), and therefore it would be extremely impractical to download all the files every time the update notification is fired (if I had 5 files , and this is called 4 times, I would quickly open 20 UIDocs). For example, this happens if I update one file (and only have one file in my ubiquitous container):

 2012-07-05 10:51:39.565 Meernotes[7842:707] ... NSMetadataQuery update 2012-07-05 10:51:42.468 Meernotes[7842:707] ... NSMetadataQuery update 2012-07-05 10:51:45.216 Meernotes[7842:707] ... NSMetadataQuery update 2012-07-05 10:51:47.036 Meernotes[7842:707] ... NSMetadataQuery update 

Is there any other way to determine when a file has changed? NSFileVersion did not help either.

+2
source share
1 answer

NSMetadataQueryDidUpdateNotification occurs every time some of the attributes of any NSMetadataItem in NSMetadataQuery update the results. It includes partial download or download. Therefore, it is not recommended that you try to open an instance of UIDocument during this notification processing.

Instead, you can determine when the document loaded by observing the values โ€‹โ€‹of the NSMetadataItem attribute, and then the queue to open it.

Remember to also handle the NSMetadataQueryDidFinishGatheringNotification . It is sent when the receiver has finished with the original result - request collection phase

+3
source

Source: https://habr.com/ru/post/1444028/


All Articles