NKIssue下载由于网络不可用而终止后会发生什么? [英] What happened after NKIssue download terminated due to network unavailability?

查看:151
本文介绍了NKIssue下载由于网络不可用而终止后会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NewsStand应用程序,当用户点击下载按钮时,我们会使用

I have a NewsStand app where when user taps on download button we download issue using

[nkAsset下载downloadWithDelegate:self];

[nkAssetDownload downloadWithDelegate:self];

现在在两次下载之间,假设网络断开连接,NSURLConnection调用didFailWithError:(NSError *)error方法.我会通过警报通知用户并更新UI,以便启用下载按钮.现在,当用户点击下载"按钮时,我会检查

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){再次开始下载 与[nkIssue.downloadingAssets objectAtIndex:0]一起使用; }其他{开始 使用nkAssetDownload = [nkIssue下载 addAssetWithRequest:urlRequest]; }

if(nkIssue.downloadingAssets.count == 1) { again start download with [nkIssue.downloadingAssets objectAtIndex:0]; } else { start download with nkAssetDownload = [nkIssue addAssetWithRequest:urlRequest]; }

对此我几乎没有疑问

1)为什么当用户再次点击下载"按钮时,我总是得到nkIssue.downloadingAssets.count == 0?不是应该是iOS的下载队列中仍然存在的问题吗?

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)用户再次点击下载"后,问题应该继续从相同位置下载吗?我并不总是观察到这种现象,有时它会从头开始下载(叹气).

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

尽管如果我关闭应用程序,将其从内存中删除(双击主屏幕按钮,长按应用程序图标并删除它),然后再次启动,我确实在"didFinishLaunchingWithOptions"中获得了[nkLib downloadingAssets] .count == 1,并且我的问题恢复下载.

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.

Apple并未明确记录NewsStand内容的各个方面.

Every aspect of NewsStand stuff is not clearly documented by Apple.

推荐答案

如果您想进一步研究并且没有更好的主意,我有两种理论:

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

  1. 我很惊讶NSURLConnection调用didFailWithError.我希望下载资产保留在downloadingAssets中,以后会自动重试.我对此的理论是: didFailWithError方法是可选的,并且报亭工具包的行为会有所不同,具体取决于您是否实现此方法. NSURLConnection可以检查委托是否响应该方法来做出此决定.如果实现该方法并且出现网络错误,则使用didFailWithError方法报告该错误.该方法执行完后,下载资源将从库中删除.如果您未实现该方法,则下载将不会失败,并且报亭工具包将处理任何错误:下载资源将保留在队列中,并将无限期重试(就您的软件而言,下载将永远不会失败) ).

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

如果下载失败(或完成),则使用didFailWithError(或connectionDidFinishDownloading)委托回调方法通知您.在该方法完成之前,可能不会从downloadingAssets中删除下载资产.如果您在方法期间显示警报,则当用户再次按下下载"按钮时,资产将不存在.

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.

这篇关于NKIssue下载由于网络不可用而终止后会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆