|
|
@@ -597,4 +597,70 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
|
|
|
//[task cancel];
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark afnetwork get 请求 音乐播放器下载音频缓存
|
|
|
+- (void)cloudPhoneDownloadAudioByCode:(NSString*)code withSavePath:(NSString*)savePath success:(netWork_Success)success failure:(netWork_Faild)failure
|
|
|
+{
|
|
|
+
|
|
|
+ NSString *curServer = code;
|
|
|
+ NSString *fullUrl = curServer;
|
|
|
+ HLog(@"地址:%@",fullUrl);
|
|
|
+
|
|
|
+ //managerNAS manager
|
|
|
+ //[managerNAS.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
|
|
+
|
|
|
+ __block SuperModel *model = [SuperModel new];
|
|
|
+
|
|
|
+ if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
|
|
|
+ {// 无网络状态
|
|
|
+ model.code = -1;
|
|
|
+ success(model);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!fullUrl){
|
|
|
+ model.code = -1;
|
|
|
+ success(model);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if([fullUrl containsString:@"getFile"]
|
|
|
+ &&![fullUrl containsString:@"getFiles"]){
|
|
|
+ fullUrl = [fullUrl stringByReplacingOccurrencesOfString:@"getFile" withString:@"getFiles"];
|
|
|
+ }
|
|
|
+ HLog(@"%@",fullUrl);
|
|
|
+
|
|
|
+ //1.创建管理者对象
|
|
|
+ AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
|
|
+ //2.确定请求的URL地址
|
|
|
+ NSURL *url2222 = [NSURL URLWithString:fullUrl];
|
|
|
+ //3.创建请求对象
|
|
|
+ NSURLRequest *request = [NSURLRequest requestWithURL:url2222];
|
|
|
+ //4.下载任务
|
|
|
+
|
|
|
+
|
|
|
+ __block NSURLSessionDownloadTask *task = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
|
|
|
+ //打印下下载进度
|
|
|
+ HLog(@"%@",downloadProgress);
|
|
|
+
|
|
|
+ } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
|
|
|
+ //设置文件保存路径
|
|
|
+ return [NSURL fileURLWithPath:savePath];
|
|
|
+ } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
|
|
|
+ //HLog(@"完成cache:%@",filePath);
|
|
|
+ NSHTTPURLResponse *response1 = (NSHTTPURLResponse *)response;
|
|
|
+ NSInteger statusCode = [response1 statusCode];
|
|
|
+ HLog(@"statusCode:%ld",statusCode);
|
|
|
+ if (statusCode == 200) {
|
|
|
+ model.code = 0;
|
|
|
+ success(model);
|
|
|
+ }else{
|
|
|
+ model.code = -1;
|
|
|
+ success(model);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ //5.开始启动下载任务
|
|
|
+ [task resume];
|
|
|
+}
|
|
|
@end
|