ios UIDocumentMenuViewController不显示文件

时间:2017-12-19 12:57:50

标签: ios objective-c iphone uidocumentpickerviewcontroller

我想从文件列表中导入文件。我使用了UIDocumentMenuViewController来显示和选择文件。打开iCloud时显示空白屏幕。enter image description here

我创建了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尝试相同的东西但是同样的问题。我无法识别问题,任何人都有任何想法吗?

0 个答案:

没有答案