ASIHTTPRequest實現斷點下載

來源:互聯網
上載者:User

標籤:rails   send   one   format   targe   time   string   show   bundle   

- (IBAction)URLFetchWithProgress:(id)sender{[startButton setTitle:@"Stop" forState:UIControlStateNormal];[startButton addTarget:self action:@selector(stopURLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];NSString*tempFile = [[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent]stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.download"];if ([[NSFileManager defaultManager] fileExistsAtPath:tempFile]) {[[NSFileManager defaultManager] removeItemAtPath:tempFile error:nil];}[self resumeURLFetchWithProgress:self];}- (IBAction)stopURLFetchWithProgress:(id)sender{networkQueue = [[ASINetworkQueue alloc] init];timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:selfselector:@selector(updateBandwidthUsageIndicator) userInfo:nil repeats:YES];timer = nil;[startButton setTitle:@"Stop" forState:UIControlStateNormal];[startButton addTarget:self action:@selector(URLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];[networkQueue cancelAllOperations];[resumeButton setEnabled:YES];}- (IBAction)resumeURLFetchWithProgress:(id)sender {[resumeButton setEnabled:NO];[startButton setTitle:@"Start" forState:UIControlStateNormal]; [startButton addTarget:self action:@selector(stopURLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];[networkQueue cancelAllOperations];[networkQueue setShowAccurateProgress:YES];[networkQueue setDownloadProgressDelegate:progressIndicator];[networkQueue setDelegate:self];[networkQueue setRequestDidFinishSelector:@selector(URLFetchWithProgressComplete:)];ASIHTTPRequest*request=[[[ASIHTTPRequest alloc] initWithURL:[NSURLURLWithString:@"http://9991.net/blog/mp3/2.mp3"]] autorelease];[request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.mp3"]];[request setTemporaryFileDownloadPath:[[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent]stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.down"]];[request setAllowResumeForFileDownloads:YES];[networkQueue addOperation:request];[networkQueue go];}- (void)URLFetchWithProgressComplete:(ASIHTTPRequest *)request{if ([request error]) {fileLocation.text=[NSString stringWithFormat:@"An error occurred:%@",[[[requesterror] userInfo] objectForKey:@"Title"]];} else {fileLocation.text=[NSString stringWithFormat:@"File downloaded to %@",[requestdownloadDestinationPath]];}[startButton setTitle:@"Start" forState:UIControlStateNormal];[startButton addTarget:self action:@selector(URLFetchWithProgress:)forControlEvents:UIControlEventTouchUpInside];}- (IBAction)throttleBandwidth:(id)sender{if ([(UIButton *)sender state] ==YES) {[ASIHTTPRequest setMaxBandwidthPerSecond:ASIWWANBandwidthThrottleAmount];} else {[ASIHTTPRequest setMaxBandwidthPerSecond:];}}

ASIHTTPRequest實現斷點下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.