ICloud Drive Directory Lists and Files via NSMetadataQuery

I created an iCloud enabled app named "rmc". My app can now upload files to iCloud Drive and get metadata using NSMetadataQuery. But the NSMetadataQuery results only include files in my APP container. See this link: https://developer.apple.com/videos/wwdc/2015/?id=234 this is the doc and it says NSMetadataQuery can fetch files in another APP container. What I want is that I can get all files on iCloud Drive, just like Document 5 and Cloud Lite, they can get all files. enter image description here

see this image. This is the Document 5 APP user interface. This APP can get iCloud Drive root information. But my application can only receive files in the "rmc" folder. I also want to get all directories and files in iCloud Drive. Like Document 5. I hope if someone can help me and understand my question because my english is pouring out. Thank! This is my code:

    - (BOOL)getFiles
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil];

    self.query = [[NSMetadataQuery alloc]init];
    self.query.predicate = [NSPredicate predicateWithFormat:@"%K like '*'",NSMetadataItemFSNameKey]; // all
    self.query.searchScopes = [NSArray arrayWithObjects:NSMetadataQueryUbiquitousDocumentsScope,NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope,nil];
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(getFilesFinished:)
     name:NSMetadataQueryDidFinishGatheringNotification
     object:nil];

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(getFilesFinished:)
     name:NSMetadataQueryDidUpdateNotification
     object:nil];

    [self.query startQuery];
    return YES;
}

      

this method used NSMetadataQuery to get metadata from iCloudDrive. And I set searchScopes = [NSArray arrayWithObjects: NSMetadataQueryUbiquitousDocumentsScope, NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope, nil];

This is Apple's documentation of this value: NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope Search for documents outside of the application container. In this search, you can find iCloud documents that the user has previously opened with the Document View Controller. This allows your application to access documents again without requiring direct user interaction. Results. NSMetadataItemURLKey attributes return a security-protected NSURL. For more information on working with secure URLs, see Security URLs in the NSURL Class Reference.

+3


source to share





All Articles