Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iosmike

macrumors member
Original poster
Apr 28, 2016
32
5
Toronto, Canada
In my app I need to pick a file from iCloud and put it in an array. But I have no idea how to grab the file picked. Please see my code below and help to finish. Thank you for your time!
For iCloud, I picked key-value storage and iCould Documents


Code:
import UIKit

import MobileCoreServices


extensionViewController: UIDocumentMenuDelegate {

    func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {

        self.presentViewController(documentPicker, animated: true, completion: nil)
    }

}



class ViewController: UIViewController  {


    var documents = [AnyObject]()

    overridefunc viewDidLoad() {

        super.viewDidLoad()

    }


    @IBActionfunc addDocuments(sender: AnyObject) {

    

        let importMenu = UIDocumentMenuViewController(documentTypes: [kUTTypeTextasString, kUTTypePDFasString], inMode: .Import)

    

        importMenu.delegate = self

    

        self.presentViewController(importMenu, animated: true, completion: nil)

    

    }



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

    

    

        let document = How to get the file here?

    

        documents.append(document)



      }


}
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.