2016-12-09 17 views
0

後で私のサーバーにアップロードするために、UIDocumentPickerControllerからファイルURLを取得する方法はありますか?実装されたテレグラムとしてファイルを送信する。今すぐicloudからファイルをダウンロードして後で送信する可能性があります。しかし、私は電報に実装する方法を学びたいですか?iCloudドライブからファイルをダウンロードせずにダウンロードしますか?

これが今の私のコードです:

func openPicker() { 
    let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: ["public.data"], inMode: UIDocumentPickerMode.Open) 
    documentPicker.delegate = self 
    documentPicker.modalPresentationStyle = UIModalPresentationStyle.FullScreen 
    self.presentViewController(documentPicker, animated: true, completion: nil) 
} 

func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) { 
    if controller.documentPickerMode == UIDocumentPickerMode.Open { 
     let fileManager = NSFileManager.defaultManager() 
     print(fileManager.fileExistsAtPath(url.path!)) 
     let data = NSData(contentsOfFile: url.path!) 
     let document = UIDocument(fileURL: url) 
    } 
} 

答えて

0

これは私のために働いた、私は、ファイルのURLを取得することができたと

let documentPickerController = UIDocumentPickerViewController(documentTypes: [ICLOUD_DOCUMENT_SEARCH_TYPE], inMode: UIDocumentPickerMode.Import) 
     documentPickerController.delegate = self 
     self.presentViewController(documentPickerController, animated: true, completion: nil) 

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

ファイルをダウンロードしなくても、それから内容を読みますURLから、NSFileManagerを使用してファイルの内容を読み取ることができます。

関連する問題