swift:从自定义应用程序加载时,iClouds 文档似乎被禁用

swift: iClouds Documents seems to be disabled when loaded from custom application

我正在尝试在我的自定义应用程序中从 iCloud 上传 PDF 文件。但是当我从我的应用程序移动到 iCloud 时,无法选择文档,它们似乎被禁用了。大多数解释都是在 Obj-C 中,所以我无法完全理解。

这里有什么问题?这是我在 swift2 中的代码:

    import UIKit
import MobileCoreServices
class ViewController: UIViewController, UIDocumentPickerDelegate, UITextViewDelegate {

    @IBOutlet weak var emailButton: UIButton!
     @IBOutlet weak var UITextField: UITextView!
    override func viewDidLoad() {

        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.

    }

    @IBAction func handleImportPickerPressed(sender: AnyObject) {
        let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeText as NSString as String], inMode: .Import)
        documentPicker.delegate = self
        presentViewController(documentPicker, animated: true, completion: nil)
    }

    func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {


        print(url)
    }

它们被禁用意味着您在 iCloud 中的文档类型与您的 selecting.Use 文档类型不匹配:

 @IBAction func handleImportPickerPressed(sender: AnyObject) {

    let documentPicker = UIDocumentPickerViewController(documentTypes:["public.data", "public.text"],inMode:  UIDocumentPickerMode.Import)
    documentPicker.delegate = self
    documentPicker.modalPresentationStyle = UIModalPresentationStyle.FormSheet
    presentViewController(documentPicker, animated: true, completion: nil)
}

还有许多其他文档类型。它们被禁用意味着它们无法被您传递的 documentTypes 读取。