首页 > 解决方案 > 没有为 UIDocumentPickerViewController 调用 didPickDocumentsAtURLs 委托

问题描述

我正在尝试使用 UIDocumentPickerViewController 并且需要针对 iOS 11.0 及更高版本的应用程序。我正在模拟器中测试 iOS 版本 11.0、12.0 和 13.4 委托方法 didPickDocumentsAtURLs 在 11.0 和 12.0 上未调用,但在 13.4 版本的 iOS 上调用。在所有情况下都会调用 documentPickerWasCancelled。

这是可以重现该问题的最小代码。我有一个只有一个按钮的主视图,下面定义了按钮点击处理程序。

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)documentPicker:(UIDocumentPickerViewController *)controller
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
}

- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
}

- (IBAction)buttonTapped:(id)sender {
    UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];

    documentPicker.delegate = self;
    [self presentViewController:documentPicker animated:YES completion:nil];
}

@end

更新:这被称为 iCloud 驱动器文件,但不是本地文件。

标签: iosobjective-cuidocumentpickerviewcontroller

解决方案


推荐阅读