My app have to download a pretty big file ( 390Mb), I'm using TCBlopDownloadSwift for the download ( I converted it for swift 2.0 and it works fine) and I made the config for a background download . I want , when the app force quit to be able to resume the download . I found that when the app quit I can still found the downloaded data in the cache (in "com.apple.nsurlsessiond/Downloads/" + bundleIdentifier ) as a tmp file . But When I try to get the data of the download using :
func dataInCacheForName (name : String) -> NSData? {
let PathToCache = (NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.CachesDirectory , .UserDomainMask, true)[0] as NSString).stringByAppendingPathComponent("com.apple.nsurlsessiond/Downloads/" + bundleIdentifier)
let path = (PathToCache as NSString).stringByAppendingPathComponent(name)
let data = NSData(contentsOfFile: path)
print("data : \(data?.length)")
return data
}
it returns nil , but the file isn't nil . I can move the file , so I tried to move the file in the Documents . But then if I try to resume the download with the data , I get errors :
-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
Invalid resume data for background download. Background downloads must use http or https and must download to an accessible file.
and in the URLSession
(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError sessionError: NSError?)
error userInfo : Optional([:])
: Optional(Error Domain=NSURLErrorDomain Code=-3003 "(null)")
error code -3003 means impossible to write to file
I've read many post and yet can't find an answer
the most promising was https://forums.developer.apple.com/thread/24770