iosnewsstand-kit

Cancel NKAssetDownload works, redownloading doesn't. Any solution?


Can anyone explain me how to cancel and retry an NKAssetDownload?

Currently I tried this:

NKAssetDownload * download = [issue.downloadingAssets objectAtIndex:0];
currentConnection = [download downloadWithDelegate:self];

To cancel the download I do:

 [currentConnection cancel];

This works, however the NKAssetDownload stays in the NKIssue downloadingAssets table. Next time I want to download the same issue I execute the same code again ( downloadWithDelegate ). However this doesn't do anything. It is as if the NKAssetDownload instance still uses the same NSURLConnection that I previously canceled so it doesn't launch the download. The real problem is that I cannot remove the NKAssetDownload from the NKIssue and therefore cannot create a new one pointing at the same URL to retry the download. As far as I can tell there is no way of canceling a download and retrying it later, other than deleting the NKIssue from the library (which throws away everything) and recreating it. Does anyone know how to do this?

There is a related question on S.O. Is it possible to cancel an NKAssetDownload? but the only solution provided there is to delete the NKIssue, and that is not what I want to do.


Solution

  • Newsstand download queues are maintained by Newsstand framework. There is no control given to developers to pause/cancel downloads (except to delete NKIssue from NKLibrary).

    You can implement below method of NSURLConnectionDelegate to retry any failed download.

    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    

    I checked that if download fails and this method called nkIssue.downloadingAssets.count is always 0. You can add your issues's assets again and can start download.

    If you want to pause NS download, I am afraid there is no way. If you want to cancel download only way is to delete NKIssue fron NKLibrary, which I think has no problem. You can always add NKIssue again and start download anytime later.