English 中文(简体)
Handling Broken Portal
原标题:Handling Broken Download

I have designed an application which will download some data from the server, and all is working fine if there is no network issue. However if there is some network fluctuation during download some data will not be downloaded and the app will crash. Here I need some help from you guys. Is it possible for me to write a separate code to handle such situation and re-download the entire data by deleting the incomplete downloaded data. Thank you in advance,

问题回答

Yes. you can do that.
There are two situation
1. Network not available.
- -> To fix this you have to use "Rechability" sample code(Provided by Apple). Before start downloading you have to check for internet availability.
- ->Or if you are not checking for internet rechability then you will got error code(404) in delegate method of NSURL connection:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
2. Network Fluctuation.
Here I mean in between downloading if network fluctuate. Then it will call below method
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
You can handle all the things inside this method

如果存在任何网络波动或类似的问题,如果你正在使用NSURLConnection或任何其他网络工具,那么你就应当获得吉大港山区的错误代码。 您可以利用这一方法删除未完全下载的数据,并向控制器编码提供信息,以便它能够决定是否重载。

Aditya is right. Assume that you are using NSURLConnection If your connection breaks you can read the response code using the following delegate method,

- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
     NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
     int responseStatusCode = [httpResponse statusCode];
}

并且你可以着手停止连接并删除尚未完成的下载数据。


对评论的最新答复。

如果你在不同的班级使用不同的连接,那么每班就应当实施。 我认为,你应该有某种设计,某个特定类别将处理所有相关任务。 (5月份胜诉符合你的要求)。 但是,为了你目前的设计,你应在你的所有班子里使用。





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签