Changes to NSMetadataQueryDidUpdate functionality in ios 11

I have an unrelease UIDocuments app in development that adds Observers for NSMetadataQueryDidFinishGathering and NSMetadataQueryDidUpdate. It calls the same routine for both notifications which handlers them by using the results from the NSMetadataQuery and updating the list of URLs from the cloud. All of this has worked for more than a year and is programmed according to Apples documentation. It is also the same implementation as presented by Ray Wenderlich in "ICloud and UIDocuments Beyond the Basics" from 2012.


Part of the process is to open the UIDocument file/fileWrapper to harvest information for display in a tableView.


With the introduction of ios 11, I am having a problem. The act of opening a UIDocument causes a new NSMetadataQueryDidUpdate notification which causes me to reload the URLs and open the UIdocuments which causes a new NSMetadataQueryDidUpdate notification... until the app crashes.


The same thing happens with Ray's App.


Opening a UIDocument did not cause a NSMetadataQueryDidUpdate notification before ios 9.


I looked through the Apple Documents and WWDC videos to see if there was a defined solution for this but I did not find one.


Is this a bug or what can I do to fix this?

Post not yet marked as solved Up vote post of Sojourner9 Down vote post of Sojourner9
1.3k views

Replies

Hi. I observe that opening a UIDocument on iOS 11 (or a NSDocument on macOS 10.13) an extended attribute named com.apple.lastuseddate#PS is updated on the iCloud document. The updated extended attribute is propogated by iCloud.


The inode modification time (ctime) and file access time (atime) are updated at the time the extended attribute is updated. However the file contents modification date is left unchanged.


I haven't seen any documentation of this behaviour but strongly suspect it relates to the new NSFileProviderExtension method setLastUsedDate:forItemIdentifier:completionHandler:


So I expect you will have to get used to this change and be more discriminating in deciding when to reload the UIDocument.