首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

文件异步上载

2013-01-23 
文件异步下载- (void)onDownloaderReceivedData:(IMIDownloader *)aDownloader { NSLog(@"%@\t\tProg

文件异步下载
- (void)onDownloaderReceivedData:(IMIDownloader *)aDownloader {
NSLog(@"%@\t\tProgress:%.2f%%", aDownloader.uuid, aDownloader.progress * 100.0);
UIProgressView *p = (UIProgressView *)[window viewWithTag:[aDownloader.uuid intValue]];
p.progress = aDownloader.progress;
}

- (void)onFinishDownload:(IMIDownloader *)aDownloader {
NSLog(@"%@\t\tFinish:%@", aDownloader.uuid, aDownloader.name);
}

- (void)testDownloader {
IMIDownloadManager *dm = [IMIDownloadManager shared];
dm.delegate = (id)self;
if (![dm resume]) {
  IMIDownloader *dl = [IMIDownloader new];
  //memory size (KB) of the downloading cache, default value is 100KB
  dl.memoryCacheSize = 80;
  //uuid can be any string, but here I use an int to give tag for UIProgressView
  //that can easy trac back to update the progress
  dl.uuid = @"102";
  //give me a name, or I will guess my name
  dl.name = @"pic1.jpg";
  //customize the file, leave it blank, I can give a path
  //dl.path = @"/CUSTOMIZE/YOUR/FILE/PATH";
  dl.targetURL = @"http://dl.iteye.com/upload/attachment/0076/4387/271f6001-aaf2-3231-878a-8d74377fd17d.jpg";
  [dm addDownloader:[dl autorelease]]; //downloader will start by itself
       
  IMIDownloader *dl2 = [IMIDownloader new];
  dl2.uuid = @"4322";
  dl2.name = @"pic2.jpg";
  dl2.targetURL = @"http://dl.iteye.com/upload/attachment/0071/4676/4e0c9ec4-7485-3052-8a6b-b71520ad0838.jpg";
  [dm addDownloader:[dl2 autorelease]];
} else {
  NSLog(@"Resume Downloading!");
}

NSArray *keys = [dm.downloaders allKeys];
for (int i = 0; i

热点排行