iOS 10 で実行されている xcode 8 を使用しています。超シンプルな NSMetadataQuery をまとめようとしています。これでほぼ1日腰を下ろしました。これでクエリを実行することができましたが、My 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>
ここで何が欠けていますか?