我在代码中通过urlsession下载usdz:
let url = URL(string: "download usdz url")
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let destinationUrl = documentsUrl.appendingPathComponent(url!.lastPathComponent)
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: nil, delegateQueue: nil)
var request = URLRequest(url: url!)
request.httpMethod = "GET"
let downloadTask = session.downloadTask(with: request, completionHandler: { (location:URL?, response:URLResponse?, error:Error?) -> Void in
let fileManager = FileManager.default
try! fileManager.moveItem(atPath: location!.path, toPath: destinationUrl.path)
do {
let testEntity = try Entity.load(contentsOf: destinationUrl) // Error
}
catch {
print("\(error.localizedDescription)")
}
})
downloadTask.resume()
但此代码崩溃:
let testEntity = try Entity.load(contentsOf: destinationUrl)
.
大家有这个问题吗?