简体   繁体   中英

Accessing iCloud Drive files from app

I want to have iCloud support in my app where I can store and get PDF files. My question is "How to access iCloud drive file without using UIDocumentPickerViewController ". Actually I want to have custom files list in my app.

I tried this code

- (void) getAllFilesIniCloud
{
    queryData = [[NSMetadataQuery alloc] init];
    [queryData setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope]];
    NSPredicate *pred = [NSPredicate predicateWithFormat: @"%K like '*.'", NSMetadataItemFSNameKey];
    [queryData setPredicate:pred];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(queryDidFinishGathering:)
                                                 name:NSMetadataQueryDidFinishGatheringNotification
                                               object:queryData];
    [queryData startQuery];
}

- (void)queryDidFinishGathering:(NSNotification *)notification
{
    NSMetadataQuery *pQuery = [notification object];
    [pQuery disableUpdates];
    [pQuery stopQuery];
    [pFilesArray removeAllObjects];
    for (NSMetadataItem *item in [query results])
    {
        NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
        NSString * name = url.lastPathComponent;

        if ([[name pathExtension] isEqualToString:@"pdf"] || [[name pathExtension] isEqualToString:@"PDF"])
        {
            NSString *fileName = [url.absoluteString lastPathComponent];

            if (url && ![pFilesArray containsObject:fileName])
            {
                [pFilesArray addObject:fileName];
            }

        }
    }
    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:pQuery];

    queryData = nil;
    [pTableView reloadData];
}

and also tried the scope

NSMetadataQueryUbiquitousDataScope
NSMetadataQueryUbiquitousDocumentsScope
NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope

I know this code working fine for app directory in iCloud. But if user store file in iCloud in Mac or through web then my app should also enable to access this file.

我遇到了同样的问题,请在iCloud上通过此线程进行澄清https://forums.xamarin.com/discussion/comment/283726#Comment_283726

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM