Accessing iCloud Drive files from app

岁酱吖の 提交于 2019-12-10 15:56:35

问题


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.


回答1:


I had the same problem , please go through this thread to clarify on iCloud https://forums.xamarin.com/discussion/comment/283726#Comment_283726



来源:https://stackoverflow.com/questions/33039718/accessing-icloud-drive-files-from-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!