Reputation: 41
I would like to download a movie from a URL and save to iPhone.
I use this function
func downloadVideo(videoUrl: URL, name: String) {
let sampleURL = videoUrl.absoluteString
DispatchQueue.global(qos: .background).async {
if let url = URL(string: sampleURL), let urlData = NSData(contentsOf: videoUrl) {
let galleryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let filePath="\(galleryPath)/" + name + ".MOV"
DispatchQueue.main.async {
urlData.write(toFile: filePath, atomically: true)
}
}
}
}
But I got this error message: "Can't end BackgroundTask: no background task exists with identifier 16 (0x10), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug."
I added a symbolic breakpoint for UIApplicationEndBackgroundTaskError, but I don't understand what is wrong. What should I do to solve this problem?
Screenshot from breakpoint:
Upvotes: 0
Views: 168
Reputation: 534893
But I got this error message: "Can't end BackgroundTask: no background task exists with identifier 16 (0x10), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug."
This is a new warning only in the Simulator in Xcode 11. It’s unimportant. Ignore it. It happens all the time, nothing to do with your code.
Upvotes: 2