【发布时间】:2018-04-27 17:00:10
【问题描述】:
所以我有一个 url 链接,其中包含我想在我的应用程序中显示的内容的文本文件。但是我很难将它下载到我的应用程序中。我试图在该位置获取文本的代码目前看起来像这样
@objc func grabTextFile(){
let messageURL = URL(string: urlString)
let sharedSession = URLSession.shared
let downloadTask: URLSessionDownloadTask = sharedSession.downloadTask(with: messageURL!,completionHandler: {
(location: URL!, response: URLResponse!, error: NSError!) -> Void in
var urlContents = ""
do{
urlContents = try String(contentsOf: location, encoding: String.Encoding.utf8)
}catch {
urlContents = ""
}
print(urlContents)} as! (URL?, URLResponse?, Error?) -> Void)
downloadTask.resume()
}
消息网址是这个链接
var urlString = "18.218.88.192:8080/ActiveHoneypotWeb/logfiles/159.65.139.103-0-commands.txt"
由于某种原因,它每次都会崩溃。 谁能帮帮我?
【问题讨论】: