iOS 14 NSMetadataQuery not updating; no notifications are sent, works on iOS13

261 views Asked by At

I am using NSMetadataQuery to query a file on iCloud in an ubiquitous container. The code works as expected on iOS13.7, but it does NOT work on iOS14. On iOS 14 no notifications are sent to the app. Is this a known bug or an implementation issue with my code ?

Thanks

var m_basename = "textfile.txt"

override func viewDidLoad() {
  super.viewDidLoad()

  // check for iCloud
  if !ViewController.checkForICloud() {
    fatalError("iCloud not configured")
  }

  // Now configure the meta data query
  m_textFileQuery.searchScopes = [NSMetadataQueryUbiquitousDocumentsScope]
  m_textFileQuery.predicate = NSPredicate(format: "%K LIKE '\(m_basename)'", NSMetadataItemFSNameKey)
  m_textFileQuery.start()

  NotificationCenter.default.addObserver( self,
                                          selector:#selector(textFileQueryDidUpdate),
                                          name:NSNotification.Name.NSMetadataQueryDidFinishGathering, object:m_textFileQuery)
  NotificationCenter.default.addObserver( self,
                                          selector:#selector(textFileQueryDidUpdate),
                                          name:NSNotification.Name.NSMetadataQueryDidUpdate, object:m_textFileQuery)
}
  
@objc func textFileQueryDidUpdate(notification: NSNotification) {
  print(#function, "textFile query found \(m_textFileQuery.resultCount) file(s)")
}
0

There are 0 answers