I'm making a newsstand app, I have many download assets per issue to download. "issues" is a NSArray* requested from the server. I start downloading with iterating through all the assets like this in MyDownloader class:
for (int i=0; i< issues.count; i++)
MyIssue *currentIssue = [issues objectAtIndex:i];
NSString *filename = [currentIssue.remotePath lastPathComponent];
NSString *localFilepath = [cache.cachePath stringByAppendingString:filename];
//skip downloaded file
if ([[NSFileManager defaultManager] fileExistsAtPath:localFilepath]) {
continue;
}
NSURL *downloadURL = [NSURL URLWithString:currentIssue.remotePath];
// let's create a request and the NKAssetDownload object
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:downloadURL];
NKAssetDownload *assetDownload = [nkIssue addAssetWithRequest:req];
[assetDownload setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:
localFilepath, @"Filepath",
nil]];
// let's start download
[assetDownload downloadWithDelegate:self];
}
I'm storing localFilepath for later use in connection:didFinishDownloading:destinationURL method.
Everything is working fine, except one thing. Here's the code I put in application:didFinishLaunchingWithOptions: method
NKLibrary *nkLib = [NKLibrary sharedLibrary];
for(NKAssetDownload *asset in [nkLib downloadingAssets]) {
NSLog(@"Asset to download: %@",asset);
MyDownloader *downloader = [MyDownloader sharedDownloader];
[asset downloadWithDelegate:downloader];
}
This also works fine. But when I need to cancel all queued downloads, I comment out the previous code from application:didFinishLaunchingWithOptions:, I get log messages like this:
NewsstandKit: cleaning up abandoned asset downloads: (
"<NKAssetDownload: 0xa17ffe0> -> {identifier: '98E98868-0DD2-45FF-90B8-7CF80E02A952/B11F6C43-86CC-4434-ABC1-F4450FF163CF' request: <NSMutableURLRequest http://servername/serverpath/file.zip> downloading: NO}"
And I expect that all the downloads are cancelled. But when I look in the Library/Cache directory of an application, I see lots of files downloading with filenames starting with "bgdl-2896-" and so on. So they are not get cancelled, they are downloaded by the NewsstandKit. connection:didFinishDownloading:destinationURL method is also not called. That's the trouble - assets consumes internet traffic and storage on the device.
How can I force to cancel asset downloads I don't need any more?