问题
I have a NewsStand app where when user taps on download button we download issue using
[nkAssetDownload downloadWithDelegate:self];
Now in between downloading suppose network disconnects, NSURLConnection calls didFailWithError:(NSError *)error method. I inform this to user with an alert and update UI so that download button get enabled. Now when user taps on "download" button, I check for
if(nkIssue.downloadingAssets.count == 1) { again start download with [nkIssue.downloadingAssets objectAtIndex:0]; } else { start download with nkAssetDownload = [nkIssue addAssetWithRequest:urlRequest]; }
I have few queries about this
1) Why I always get nkIssue.downloadingAssets.count == 0 when user taps "download" button again? Should it not be 1 the issue which should still be in iOS's download queue ?
2) After user taps "download" again, issue should continue downloading from same position right ? I am not always observing this behavior, sometime it start downloading from start (sigh).
Although if I close app, removed it from memory (double tap home button, long press app icon and delete it) and again launch I do get [nkLib downloadingAssets].count == 1 in "didFinishLaunchingWithOptions" and my issue resumes download.
Every aspect of NewsStand stuff is not clearly documented by Apple.
回答1:
I have two theories if you want to investigate further and have no better ideas:
I am surprised NSURLConnection calls didFailWithError. I would have expected the downloading asset to stay in downloadingAssets and be automatically retried later. My theory on this is: The didFailWithError method is optional and Newsstand Kit behaves differently depending on whether you implement this method or not. NSURLConnection may check that the delegate responds to the method to make this decision. If you implement the method and there is a network error, the error is reported using the didFailWithError method. After that method has finished executing, the downloading asset will be removed from the library. If you don't implement the method the download will not fail and any errors will be handled by the Newsstand Kit: the downloading asset will remain in the queue and will be retried indefinitely (as far as your software is concerned the download will never fail).
If a download fails (or completes) you are informed by the didFailWithError (or the connectionDidFinishDownloading) delegate callback method. The downloading asset will probably not be removed from downloadingAssets until after that method has finished. If you present an alert during the method, the asset will not be there when the user presses the Download button again.
来源:https://stackoverflow.com/questions/9615945/what-happened-after-nkissue-download-terminated-due-to-network-unavailability