iOS开发之调用浏览

2020-03-05  本文已影响0人  chasitu

iOS8之后新出了一个UIDocumentPickerViewController这个类,这个类是调用系统公共文件夹的,就是我们手机里面的《文件APP》的,今天我就用用这个;

使用

我们直接上代码吧

- (void)presentDocumentPicker {
    NSArray *types = @[]; // 可以选择的文件类型
    UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeOpen];
    documentPicker.delegate = self;
    documentPicker.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:documentPicker animated:YES completion:nil];
}

delegate

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
//url是本地文件路径
}

我们看起来代码量不多,但是有个麻烦的事,就是我上面留的那个空数组里面要输入要读取的文件类型,官网类型,官网的类型非常多,按照需要单独的输入进去,看不明白怎么办呢? 官方文档

直接上图供大家参考


conformance_hierarchy.gif
physical_vs_functional.gif

结:根据上图和类型列表使用需要的文件类型,像我一样什么都要的直接把三个夫类放进去就可以了,(没想到最后一句是重点,哈哈哈)

上一篇下一篇

猜你喜欢

热点阅读