【问题标题】:Problem UIDocumentPickerViewController in iOS 14iOS 14 中的问题 UIDocumentPickerViewController
【发布时间】:2021-11-03 21:02:36
【问题描述】:

很抱歉这个问题,但我找不到解决方案或者我无法理解...... 直到现在我都在使用这个函数。

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        
        
         // Importo
         if controller.documentPickerMode == .import {
          
         my code
         }

       // Esporto
         if controller.documentPickerMode == .exportToService {
          may code
         }

现在,ios 14 中的 .documentPickerMode 不再存在,我怎样才能获得相同的结果?或者他会知道我是来自进口还是出口?

TKS

【问题讨论】:

    标签: swift ios14


    【解决方案1】:

    现在您必须使用四种不同的方法。两个用于导出,另外两个用于打开您指定的文档类型:


    Creates and returns a document picker that can export the types of documents you specify.

    init(forExporting: [URL])
    

    Creates and returns a document picker that can export or copy the types of documents you specify.

    init(forExporting: [URL], asCopy: Bool)
    

    Creates and returns a document picker that can open the types of documents you specify.

    init(forOpeningContentTypes: [UTType])
    

    Creates and returns a document picker that can open or copy the types of documents you specify.

    init(forOpeningContentTypes: [UTType], asCopy: Bool)
    

    然后在调用时切换控制器:

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
    
        switch controller {
            case documentExporter:
                print("documentExporter")
            case documentImporter:
                print("documentImporter")
            default: break
        }
    
    }
    

    【讨论】:

    • 您好,感谢您的回答,好的,但是当我点击要加载的文档时调用方法documentPicker(_控制器:UIDocumentPickerViewController,didPickDocumentsAt urls:[URL],然后执行一些操作,现在我该怎么办?
    • 只需切换控制器并检查哪个控制器正在调用该方法。
    • 感谢您抽出宝贵时间,我将开关置于错误通知方法“在范围内找不到'documentExporter'”
    • @Francesco 使用您选择的控制器的名称
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2022-11-09
    • 2023-03-29
    • 2021-10-04
    • 2021-02-05
    • 1970-01-01
    相关资源
    最近更新 更多