@IBAction func iCloudPlayer(_ sender: Any) {
var documentPicker = UIDocumentPickerViewController(documentTypes: ["public.txt"], in: UIDocumentPickerMode.import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = UIModalPresentationStyle.fullScreen
self.present(documentPicker, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL){
if(controller.documentPickerMode == UIDocumentPickerMode.import){
let content = openFile(path: url.path, UTF8: String.Encoding.utf8)
titlePlayerContent.text = content
}
}
func openFile(path:String, UTF8:String.Encoding = String.Encoding.utf8) -> String?{
var error: NSError?
return FileManager().fileExists(atPath: path) ? String(contentsOfFile: path, encoding: UTF8, error: &error)! : nil
}
//Arguments labels '(contentsOfFile;,encoding;, erro:)' do not match any available overloads, error on ? String(contentsOfFile: path, encoding: UTF8, error: &error)! : nilUIDocumentPickerViewController從iCloud中
任何建議傢伙上傳txt文件?我如何從iCloud上傳,不能在Swift 3上使用的教程!
你有沒有看着斯威夫特3文檔'字符串'和它的'init'方法? – rmaddy
而你的問題與'UIDocumentPickerViewController'或iCloud無關。 – rmaddy