2

我正在使用 NSMetadataQuery 在无处不在的容器中查询 iCloud 上的文件。该代码在 iOS13.7 上按预期工作,但在 iOS14 上不起作用。在 iOS 14 上,不会向应用发送通知。这是我的代码的已知错误还是实现问题?

谢谢

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)")
}
4

0 回答 0