// // AsyncSound.m // IBOSS // // Created by guan hong hou on 15/11/24. // Copyright © 2015年 elongtian. All rights reserved. // #import "AsyncSound.h" @implementation AsyncSound @synthesize response = _response; -(void)asyncLoad :(NSString *)urlString localPath:(NSString*) localFilePath{ urlStr=urlString; localPath=localFilePath; fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:localPath]) { return; } NSURL * url = [NSURL URLWithString:urlStr]; NSURLRequest * urlRequest = [NSURLRequest requestWithURL:url]; [NSURLConnection connectionWithRequest:urlRequest delegate:self]; } #pragma mark - NSURLConnectionDataDelegate -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ receiveData = [[NSMutableData alloc] init]; allLength = [response expectedContentLength]; self.response = response; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [receiveData appendData:data]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ [receiveData writeToFile:localPath atomically:YES]; } #pragma mark - NSURLConnectionDelegate -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ //网络连接失败,关闭菊花 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; if (error) { NSLog(@"%@",[error localizedDescription]); } } @end