iPhone 的下载进度怎么弄?怎么得到下载请求的下载进度
解决方案 »
- 用扩展sdk的方式添加nsstring 的一个方法,要求,讲传进去的字符串变成大写,去掉所有的空格,将所有的字符a变成“;”
- ios路径问题
- ios中iCarousel相册插件如何默认选中某一个
- 请教一下,我之前是做网站开发的,要把网站弄成一个iso应用程序,什么学习途径最好?
- 请问如何在一个view中 增加两个navigation controller 如图~
- Iphone 条形码扫描实例
- Iphone和andorid手机 可能直接通信吗??
- 求救,NSOutputStream exc_bad_access导致 crash
- 在类中声音的变量不用进行Release吗?为什么应用报:EXC_BAD_ACCESS
- xcode6真机测试的时候碰到如下问题
- 手机通信原理
- iphone如何写代码去访问webservice?
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//判断接受数据是否正确
NSHTTPURLResponse *res=(NSHTTPURLResponse *)response;
ringht = [res statusCode];
//if (ringht == 206) {
// //如果正确打开输出流
//
// NSString *openfile = [[NSString alloc] initWithFormat:@"%@%d.am", controller.Myfilenmame, controller.count];
// self.filestream=[NSOutputStream outputStreamToFileAtPath:[self FilePathByName:openfile] append:YES];
// [self.filestream open];
// }
}//接收数据后回调
- (void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data {
if (ringht == 206) {
NSString *openfile = [[NSString alloc] initWithFormat:@"%@%d.tmp", controller.Myfilenmame, controller.count];
self.filestream=[NSOutputStream outputStreamToFileAtPath:[self FilePathByName:openfile] append:YES];
[self.filestream open];
if (controller.Sueper) {
[self.filestream close];
[self.connection cancel];
}
else {
//将数据追加方式写出
[self.filestream write:[data bytes] maxLength:[data length]];
//修改进度条
self.Acturelength += [data length];
[_mydownCondition lock];
controller.Acturelength=controller.Acturelength+[data length];
controller.progress.progress= (controller.Acturelength*1.0)/controller.Myfilelength;
[_mydownCondition unlock];
}
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//得到要下载文件的文件大小、文件名称
long length=[response expectedContentLength];
self.Myfilenmame=[response suggestedFilename];
self.Myfilelength=length;
//将文件名显示
self.label.text=Myfilenmame;
long firstleng = self.Myfilelength/3;
for (int i=0; i<2; i++) {
[self.r release];
self.r = [[NSMutableURLRequest alloc] initWithURL: url];
NSString *range = [[NSString alloc] initWithFormat:@"bytes=%d-%d", i*firstleng, (i+1)*firstleng];
[self.r setValue:range forHTTPHeaderField:@"Range"];
[range release];
NSString *tempname = [[NSString alloc] initWithFormat:@"%@%d.tmp", self.Myfilenmame, i];
TheardDown *threadload = [[TheardDown alloc] init];
[threadload init_all:tempname controllers:self mylength:firstleng myrequest:self.r];
[theards addObject:threadload];
[threadload release];
[tempname release];
}
self.r = [[NSMutableURLRequest alloc] initWithURL: url];
NSString *range = [[NSString alloc] initWithFormat:@"bytes=%d-", 2*firstleng];
[self.r setValue:range forHTTPHeaderField:@"Range"];
[range release];
TheardDown *threadload = [[TheardDown alloc] init];
NSString *tempname = [[NSString alloc] initWithFormat:@"%@%d.tmp", self.Myfilenmame, 2];
[threadload init_all:tempname controllers:self mylength:(self.Myfilelength - 2*firstleng) myrequest:self.r];
[theards addObject:threadload];
[threadload release];
[tempname release];
//设置几根线程在下载
self.count = 3;
[self.connection cancel];
}
[downloadRequest setDownloadProgressDelegate: progressView];只要下载的进度改变 进度条(progressView)就可以自动改变
我的问题是如何在现实?%的时候可以自动更新显示 而不是手动的一直重复调用函数 重复调用函数会影响其他线程的运行。不知道上述方法可不可以实现啊???学习中
请到我的博客 http://blog.csdn.net/fanxiaoduo