Commit 137a7ecc387bbe021794c1913775b85d2c81da9b
1 parent
bc579b50
提交0.1.18
Showing
4 changed files
with
2 additions
and
212 deletions
CNLiveUploadManager.podspec
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | Pod::Spec.new do |s| | 9 | Pod::Spec.new do |s| |
| 10 | s.name = 'CNLiveUploadManager' | 10 | s.name = 'CNLiveUploadManager' |
| 11 | - s.version = '0.1.7' | 11 | + s.version = '0.1.8' |
| 12 | s.summary = '压缩上传,组件化中加入新参数加入outPath,不在直接取' | 12 | s.summary = '压缩上传,组件化中加入新参数加入outPath,不在直接取' |
| 13 | 13 | ||
| 14 | # This description is used to generate tags and improve search results. | 14 | # This description is used to generate tags and improve search results. |
CNLiveUploadManager/Classes/CNLiveUploadManager.h
| @@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
| 19 | #import <CNLiveUserManagement/CNUserInfoModel.h> | 19 | #import <CNLiveUserManagement/CNUserInfoModel.h> |
| 20 | #import <CNLiveUserManagement/CNUserInfoManager.h> | 20 | #import <CNLiveUserManagement/CNUserInfoManager.h> |
| 21 | #import <CNLiveBaseTools/CNLiveTimeTools.h> | 21 | #import <CNLiveBaseTools/CNLiveTimeTools.h> |
| 22 | -#import "HttpService.h" | 22 | +#import <CNLiveBusinessTools/HttpService.h> |
| 23 | #import <AFNetworking/AFNetworking.h> | 23 | #import <AFNetworking/AFNetworking.h> |
| 24 | #import <YYKit/YYKit.h> | 24 | #import <YYKit/YYKit.h> |
| 25 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> | 25 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> |
CNLiveUploadManager/Classes/HttpService.h deleted
100644 → 0
| 1 | -// | ||
| 2 | -// HttpService.h | ||
| 3 | -// ZXBaseProject | ||
| 4 | -// | ||
| 5 | -// Created by 张旭 on 2017/1/12. | ||
| 6 | -// Copyright © 2017年 cnlive. All rights reserved. | ||
| 7 | -// | ||
| 8 | - | ||
| 9 | -//////////////////////////////////////////////////////// | ||
| 10 | -//////////// 基础网络请求 | ||
| 11 | -//////////////////////////////////////////////////////// | ||
| 12 | - | ||
| 13 | -#import <Foundation/Foundation.h> | ||
| 14 | - | ||
| 15 | -typedef NS_ENUM(NSUInteger, HTTP_REQUEST_METHOD) { | ||
| 16 | - E_HTTP_REQUEST_METHOD_GET = 0, | ||
| 17 | - E_HTTP_REQUEST_METHOD_POST, | ||
| 18 | -}; | ||
| 19 | - | ||
| 20 | -typedef void(^completionHandler)(id data,NSError *error); | ||
| 21 | - | ||
| 22 | -@interface HttpService : NSObject | ||
| 23 | - | ||
| 24 | -/** 单例 */ | ||
| 25 | -+ (HttpService*)service; | ||
| 26 | - | ||
| 27 | -/** 清除所有任务 */ | ||
| 28 | -- (void)cleanAllTask; | ||
| 29 | - | ||
| 30 | -/** 所有网络请求的基础 */ | ||
| 31 | -- (NSURLSessionDataTask *)sendRequestWithHttpMethod:(HTTP_REQUEST_METHOD)method URLPath:(NSString *)pathStr parameters:(id)parameters isCache:(BOOL)isCache CheckParam:(NSArray *)checkParam completionHandler:(completionHandler)completionHandler DEPRECATED_MSG_ATTRIBUTE("Please use CNLiveNetworking"); | ||
| 32 | - | ||
| 33 | -@end |
CNLiveUploadManager/Classes/HttpService.m deleted
100644 → 0
| 1 | -// | ||
| 2 | -// HttpService.m | ||
| 3 | -// ZXBaseProject | ||
| 4 | -// | ||
| 5 | -// Created by 张旭 on 2017/1/12. | ||
| 6 | -// Copyright © 2017年 cnlive. All rights reserved. | ||
| 7 | -// | ||
| 8 | - | ||
| 9 | -#import "HttpService.h" | ||
| 10 | -#import <AFNetworking/AFNetworking.h> | ||
| 11 | -#import <CNLiveRequestBastKit/CNLiveNetworking.h> | ||
| 12 | -#import <MJExtension/MJExtension.h> | ||
| 13 | -#import <YYKit/YYKit.h> | ||
| 14 | - | ||
| 15 | -static NSString *errorCode = @"errorCode"; | ||
| 16 | -static NSString *errorMessage = @"errorMessage"; | ||
| 17 | -static NSString *requestData = @"data"; | ||
| 18 | - | ||
| 19 | -@interface HttpService () | ||
| 20 | -{ | ||
| 21 | - AFHTTPSessionManager *_dataSessionManager; | ||
| 22 | -} | ||
| 23 | - | ||
| 24 | -@end | ||
| 25 | - | ||
| 26 | -@implementation HttpService | ||
| 27 | - | ||
| 28 | -#pragma mark - | ||
| 29 | -#pragma mark - SINGLETON | ||
| 30 | - | ||
| 31 | -static HttpService * __singleton__; | ||
| 32 | - | ||
| 33 | -+ (HttpService *)service { | ||
| 34 | - static dispatch_once_t predicate; | ||
| 35 | - dispatch_once( &predicate, ^{ __singleton__ = [[[self class] alloc] init]; } ); | ||
| 36 | - return __singleton__; | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -#pragma mark - | ||
| 40 | -#pragma mark - Init | ||
| 41 | - | ||
| 42 | -- (instancetype)init { | ||
| 43 | - self = [super init]; | ||
| 44 | - if (self) { | ||
| 45 | - [self initManagers]; | ||
| 46 | - } | ||
| 47 | - return self; | ||
| 48 | -} | ||
| 49 | - | ||
| 50 | -/** 所有网络请求的基础 */ | ||
| 51 | -- (NSURLSessionDataTask *)sendRequestWithHttpMethod:(HTTP_REQUEST_METHOD)method URLPath:(NSString *)pathStr parameters:(id)parameters isCache:(BOOL)isCache CheckParam:(NSArray *)checkParam completionHandler:(completionHandler)completionHandler | ||
| 52 | -{ | ||
| 53 | - CNLiveRequestMethod requestMethod = method == E_HTTP_REQUEST_METHOD_POST ? CNLiveRequestMethodPOST : CNLiveRequestMethodGET; | ||
| 54 | - CNLiveNetworkCacheType networkCacheType = isCache ? CNLiveNetworkCacheTypeCacheNetwork : CNLiveNetworkCacheTypeNetworkOnly; | ||
| 55 | - [CNLiveNetworking setupDome:NO]; | ||
| 56 | - [CNLiveNetworking setupShowDataResult:NO]; | ||
| 57 | - [CNLiveNetworking setAllowRequestDefaultArgument:YES]; | ||
| 58 | - return (NSURLSessionDataTask *)[CNLiveNetworking requestNetworkWithMethod:requestMethod URLString:pathStr Param:parameters==nil?@{}:parameters CacheType:networkCacheType CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | ||
| 59 | - NSDictionary * responseObjectDic = [responseObject mj_keyValues]; | ||
| 60 | - | ||
| 61 | - if (error) { | ||
| 62 | - if (completionHandler) completionHandler(responseObject, error); | ||
| 63 | - return; | ||
| 64 | - } | ||
| 65 | - NSString *resultCode = [NSString stringWithFormat:@"%@", responseObjectDic[errorCode]]; | ||
| 66 | - NSError *err = nil; | ||
| 67 | - id data = nil; | ||
| 68 | - if([resultCode isEqualToString:@"0"]) { | ||
| 69 | - data = responseObjectDic[requestData]; | ||
| 70 | - } else { | ||
| 71 | - @try { | ||
| 72 | - err = [[NSError alloc] initWithDomain:responseObjectDic[errorMessage] code:[resultCode integerValue] userInfo:nil]; | ||
| 73 | - } @catch (NSException *exception) { | ||
| 74 | - err = [[NSError alloc] initWithDomain:@"接口异常" code:500 userInfo:nil]; | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - if (completionHandler) completionHandler(data, err); | ||
| 78 | - }]; | ||
| 79 | - /* | ||
| 80 | - dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 81 | - [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; | ||
| 82 | - | ||
| 83 | - }); | ||
| 84 | - NSMutableDictionary *para = [CNLiveBusinessTools encryptionSignWithParameter:[NSMutableDictionary dictionaryWithDictionary:parameters] encryptionKey:APPKey]; | ||
| 85 | - NSString *urlStr = [[NSURL URLWithString:pathStr relativeToURL:_dataSessionManager.baseURL] absoluteString]; | ||
| 86 | - NSString *methodStr = [self stringWithMethod:method]; | ||
| 87 | - | ||
| 88 | - if (completionHandler && isCache) { | ||
| 89 | - [CNHttpLocalServer cacheForURL:urlStr parameters:para CheckParam:checkParam == nil ?@[]:checkParam withBlock:^(id<NSCoding> object) { | ||
| 90 | - if (object != nil) completionHandler(object,nil); | ||
| 91 | - }]; | ||
| 92 | - } | ||
| 93 | - NSDictionary * dic = [CNHttpLocalServer cacheForURL:urlStr parameters:para CheckParam:checkParam == nil ?@[]:checkParam]; | ||
| 94 | -// [IMAPlatform sharedInstance].isConnected | ||
| 95 | - if (![[[NSUserDefaults standardUserDefaults] objectForKey:CNConnectSuccNotification] boolValue] && dic == nil && completionHandler) { | ||
| 96 | - completionHandler(nil,[NSError errorWithDomain:@"暂无网络" code:-1001 userInfo:nil]); | ||
| 97 | - return nil; | ||
| 98 | - }; | ||
| 99 | - NSMutableURLRequest *request = [_dataSessionManager.requestSerializer requestWithMethod:methodStr URLString:urlStr parameters:para error:nil]; | ||
| 100 | - __block NSURLSessionDataTask *task = nil; | ||
| 101 | - task = [_dataSessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {// | ||
| 102 | - [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; | ||
| 103 | - NSError *err = nil; | ||
| 104 | - id data = nil; | ||
| 105 | - if(error ) { | ||
| 106 | - err = error; | ||
| 107 | -#if DEBUG | ||
| 108 | - [[CNNetworkLogManager defaultManager] showErrorLogWithResponse:error]; | ||
| 109 | -#else | ||
| 110 | - if (error.code == 500 || error.code == 404) return; | ||
| 111 | -#endif | ||
| 112 | - }else { | ||
| 113 | - NSDictionary * responseObjectDic = [responseObject mj_keyValues]; | ||
| 114 | - | ||
| 115 | - NSString *resultCode = [NSString stringWithFormat:@"%@", responseObjectDic[errorCode]]; | ||
| 116 | - | ||
| 117 | - if([resultCode isEqualToString:@"0"]) { | ||
| 118 | - data = responseObjectDic[requestData]; | ||
| 119 | - } else { | ||
| 120 | - @try { | ||
| 121 | - err = [[NSError alloc] initWithDomain:responseObjectDic[errorMessage] code:[resultCode integerValue] userInfo:nil]; | ||
| 122 | - } @catch (NSException *exception) { | ||
| 123 | - NSLog(@"获取到的异常是===>%@ ===>%@",exception,urlStr); | ||
| 124 | - err = [[NSError alloc] initWithDomain:@"接口异常" code:500 userInfo:nil]; | ||
| 125 | - } | ||
| 126 | - } | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 130 | - completionHandler(data, err); | ||
| 131 | - if ((data || [CNHttpLocalServer cacheForURL:urlStr parameters:para CheckParam:checkParam == nil ?@[]:checkParam] == nil) && isCache) { | ||
| 132 | - [CNHttpLocalServer setCache:data URL:urlStr parameters:para CheckParam:checkParam == nil ? @[]:checkParam]; | ||
| 133 | - } | ||
| 134 | - }); | ||
| 135 | - | ||
| 136 | - }]; | ||
| 137 | - [task resume]; | ||
| 138 | - return task; | ||
| 139 | - */ | ||
| 140 | -} | ||
| 141 | - | ||
| 142 | -- (NSString *)stringWithMethod:(HTTP_REQUEST_METHOD)method { | ||
| 143 | - switch (method) { | ||
| 144 | - case E_HTTP_REQUEST_METHOD_GET: return @"GET"; break; | ||
| 145 | - case E_HTTP_REQUEST_METHOD_POST: return @"POST"; break; | ||
| 146 | - default: | ||
| 147 | - break; | ||
| 148 | - } | ||
| 149 | - return @""; | ||
| 150 | -} | ||
| 151 | -/** 清除所有任务 */ | ||
| 152 | -- (void)cleanAllTask { | ||
| 153 | - [self invalidateManagers]; | ||
| 154 | - [self initManagers]; | ||
| 155 | - [CNLiveNetworking cancelAll]; | ||
| 156 | -} | ||
| 157 | - | ||
| 158 | -- (void)invalidateManagers { | ||
| 159 | -// [_dataSessionManager invalidateSessionCancelingTasks:YES]; | ||
| 160 | - | ||
| 161 | -} | ||
| 162 | - | ||
| 163 | -#pragma mark - | ||
| 164 | -#pragma mark - Ptavite Methods | ||
| 165 | -- (void)initManagers { | ||
| 166 | - | ||
| 167 | -// _dataSessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:nil]; | ||
| 168 | -// [_dataSessionManager setRequestSerializer:[AFHTTPRequestSerializer serializer]]; | ||
| 169 | -// [_dataSessionManager.requestSerializer setTimeoutInterval:kTimeoutInterval]; | ||
| 170 | -//// [_dataSessionManager setResponseSerializer:[AFJSONResponseSerializer serializer]]; | ||
| 171 | -//// _dataSessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"image/jpeg",@"text/javascript",@"application/json",@"text/json",@"text/plain",nil]; | ||
| 172 | -// _dataSessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"text/json", @"text/javascript", nil]; | ||
| 173 | - | ||
| 174 | - | ||
| 175 | -} | ||
| 176 | - | ||
| 177 | -@end |