【发布时间】:2015-02-20 04:18:44
【问题描述】:
我有一个简单的 NSURLConnection,我想获取解析数据的进度百分比。那就是加载的百分比。是否可以计算。 这个我试过了,
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
urlData = [NSMutableData data];
[urlData setLength:0];
expectedBytes = [response expectedContentLength];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
float progressive = (float)[urlData length] / (float)expectedBytes;
}
这里,expectedBytes 正在获取 -1。 json 链接正在获取 jsonResult。
让我知道如何计算加载进度。
【问题讨论】:
-
它必须从服务器发送以确定预期长度。也许this 会帮助你。
标签: ios objective-c nsurlconnection