I have worked out the issue. On iOS one needs to set up an NSMetadataQuery in addition to using a NSFilePresenter. Something like:
let metadataQuery = NSMetadataQuery()
metadataQuery.notificationBatchingInterval = 1
metadataQuery.searchScopes = [NSMetadataQueryUbiquitousDocumentsScope]
metadataQuery.predicate = NSPredicate(format: "%K LIKE %@", NSMetadataItemFSNameKey, "*.txt")
metadataQuery.start()
And then establish a process to listen for changes. For example using Combine:
NotificationCenter.default.publisher(for: .NSMetadataQueryDidUpdate)
.receive(on: DispatchQueue.main)
.sink { [weak self] notification in
guard let self = self else { return }
self.metadataQuery.stop()
for resultSets in 0..<self.metadataQuery.resultCount {
if let resultSet = self.metadataQuery.result(at: resultSets) as? NSMetadataItem {
/// DO YOUR MAGIC HERE...
}
}
self.metadataQuery.start()
}
.store(in: &backgroundProcesses)