使用在 iOS 10 上运行的 xcode 8。尝试组合一个超级简单的 NSMetadataQuery。腰围差不多一天了。设法让它进行查询,但它没有从我的 iCloud 返回任何文档,没有。
class ViewController: UIViewController {
var metadataQuery: NSMetadataQuery!
var metadataQueryDidUpdateObserver: AnyObject?
var metadataQueryDidFinishGatheringObserver: AnyObject?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
metadataQuery = NSMetadataQuery()
metadataQuery?.predicate = NSPredicate(format: "NSMetadataItemFSNameKey == '*'")
metadataQuery?.searchScopes = [NSMetadataQueryUbiquitousDocumentsScope, NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope]
NotificationCenter.default.addObserver(self, selector: #selector(initalGatherComplete), name: NSNotification.Name.NSMetadataQueryDidFinishGathering, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(queryStarted), name: NSNotification.Name.NSMetadataQueryDidUpdate, object: nil)
metadataQuery.start()
}
func queryStarted(notification: NSNotification) {
print("queryStarted")
}
func initalGatherComplete(notification: NSNotification) {
metadataQuery.stop()
metadataQuery.disableUpdates()
let resultCounter = metadataQuery.resultCount
print("%lu", resultCounter,metadataQuery.results)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.NSMetadataQueryDidFinishGathering, object: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
它什么也不返回,没有错误,没有数据,只是空虚的空间。现在我是的,我没有在本地保存任何文档,但我对本地文档不感兴趣,我想要 iCloud 文档。
我的 plist 是这样说的...
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.ch.cqd.iCloudQuery</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>iCloudQuery</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
我在这里想念什么?