1

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.

msk
  • 8,885
  • 6
  • 41
  • 72

1 Answers1

1

I have two theories if you want to investigate further and have no better ideas:

  1. 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).

  2. 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.

Martin Lockett
  • 2,275
  • 27
  • 31
  • "If a download fails (or completes) you are informed by a delegate callback method" -> Which callback ? connectionDidFinishDownloading ?If it called that means download completed with success. How do it inform you in case of network error ? E.g. request rejected by server. – msk Mar 21 '12 at 15:55
  • Yes, that is the delegate callback method. I will reword the theory I have described above to be clearer and to answer these questions. – Martin Lockett Mar 22 '12 at 14:54
  • Hmm now I got you. I will try it and let you know if it works. – msk Mar 23 '12 at 07:49
  • This is what I have done. Removed "didFailWithError", Changed my iPad's time by 1 hour, so that S3 rejects request made by Newsstand framework. NS framework failed to download as S3 rejected the request. After that when I checked nkIssue.status it was NKIssueContentStatusNone (that means there is nothing in queue). So it seems this theory is not correct – msk Mar 26 '12 at 11:55
  • Thanks for mentioning `connection:didFailWithError:`. I was totally missed it, because it is documented in `NSURLConnectionDelegate`. – hiroshi Aug 31 '12 at 01:19