0

我想从文件列表中导入文件。我使用 UIDocumentMenuViewController 来显示和选择文件。打开iCloud时它显示空白屏幕。在此处输入图像描述

我创建了 UIDocumentMenuViewController 来显示所有类型的文件。

UIDocumentMenuViewController *documentPickerMenu = [[UIDocumentMenuViewController alloc]
                                                    initWithDocumentTypes:@[@"public.item"]
                                                    inMode:UIDocumentPickerModeImport];
documentPickerMenu.delegate = self;
[self presentViewController:documentPickerMenu animated:YES completion:nil];

我已经实现了委托方法。

- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker{
documentPicker.delegate = self;
[self presentViewController:documentPicker animated:YES completion:nil];  }

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
if (controller.documentPickerMode == UIDocumentPickerModeImport)
{

    // Condition called when user download the file
    NSData *fileData = [NSData dataWithContentsOfURL:url];
    // NSData of the content that was downloaded - Use this to upload on the server or save locally in directory


    //Showing alert for success
    dispatch_async(dispatch_get_main_queue(), ^{

        NSString *alertMessage = [NSString stringWithFormat:@"Successfully downloaded file %@", [url lastPathComponent]];
        UIAlertController *alertController = [UIAlertController
                                              alertControllerWithTitle:@"UIDocumentView"
                                              message:alertMessage
                                              preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alertController animated:YES completion:nil];

    });
} }

我在 iCloud 上有图像。我通过创建 UIDocumentPickerViewController 而不是 UIDocumentMenuViewController 尝试了同样的事情,但同样的问题。我无法确定问题任何人都知道吗?

4

0 回答 0