| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // AsyncSound.m
- // IBOSS
- //
- // Created by guan hong hou on 17/7/24.
- // Copyright © 2017年 沈阳东科云信软件有限公司. 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
|