当前位置:编程学习 > wap >>

iPhone 的下载进度怎么弄?

iPhone 的下载进度怎么弄?怎么得到下载请求的下载进度 --------------------编程问答-------------------- 不知道.... --------------------编程问答-------------------- 在响应里面得到文件的总大小,然后根据每次下载下来的data的大小与总大小的比例,设置进度条 --------------------编程问答--------------------

- (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];


}

--------------------编程问答-------------------- 陈烨哥已经可以霸版了 --------------------编程问答--------------------
引用 5 楼 benyoulai5 的回复:
陈烨哥已经可以霸版了

左呆出现了... --------------------编程问答-------------------- 学习''''''''''''' --------------------编程问答-------------------- 学吸了  --------------------编程问答--------------------
引用 6 楼 cloudhsu 的回复:
引用 5 楼 benyoulai5 的回复:
陈烨哥已经可以霸版了

左呆出现了...

--------------------编程问答-------------------- //可以通过设置代理来自动更改进度条的运动
[downloadRequest setDownloadProgressDelegate: progressView];

只要下载的进度改变 进度条(progressView)就可以自动改变
我的问题是如何在现实?%的时候可以自动更新显示 而不是手动的一直重复调用函数 重复调用函数会影响其他线程的运行。。。。。。。

不知道上述方法可不可以实现啊???

学习中。。。。。。。。。 --------------------编程问答-------------------- iphone 父窗口与子窗口间的变量传递 各位有没有更好办法,请指教.


请到我的博客  

http://blog.csdn.net/fanxiaoduo --------------------编程问答-------------------- 那个进度的显示, 可以根据关注UIProgressView 的 progress 值 进行改变, 也可以由时间来控制,

在指定的时间内进行进度的更新。。。。
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,