Commit 72f31f8746eed656c76486499ccfdff2457852e1
1 parent
aa0bd6f5
0.1.8 ,增加HTTPService
Showing
7 changed files
with
165 additions
and
5 deletions
CNLiveBusinessTools.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 = 'CNLiveBusinessTools' | 10 | s.name = 'CNLiveBusinessTools' |
| 11 | - s.version = '0.1.7' | 11 | + s.version = '0.1.8' |
| 12 | s.summary = '业务工具集合组件.' | 12 | s.summary = '业务工具集合组件.' |
| 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. |
| @@ -41,4 +41,6 @@ Pod::Spec.new do |s| | @@ -41,4 +41,6 @@ Pod::Spec.new do |s| | ||
| 41 | s.dependency 'CNLiveEnvironment' | 41 | s.dependency 'CNLiveEnvironment' |
| 42 | s.dependency 'CNLiveUserManagement' | 42 | s.dependency 'CNLiveUserManagement' |
| 43 | s.dependency 'CNLiveBaseKit' | 43 | s.dependency 'CNLiveBaseKit' |
| 44 | + s.dependency 'CNLiveRequestBastKit' | ||
| 45 | + | ||
| 44 | end | 46 | end |
CNLiveBusinessTools/Classes/CNLiveBusinessToolsHeader.h
0 → 100644
CNLiveBusinessTools/Classes/HttpService.h
0 → 100644
| 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 |
CNLiveBusinessTools/Classes/HttpService.m
0 → 100644
| 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 | + | ||
| 11 | +#import <CNLiveRequestBastKit/CNLiveNetworking.h> | ||
| 12 | +#import <AFNetworking/AFNetworking.h> | ||
| 13 | +#import <MJExtension/MJExtension.h> | ||
| 14 | +static NSString *errorCode = @"errorCode"; | ||
| 15 | +static NSString *errorMessage = @"errorMessage"; | ||
| 16 | +static NSString *requestData = @"data"; | ||
| 17 | + | ||
| 18 | +@interface HttpService () | ||
| 19 | +{ | ||
| 20 | + AFHTTPSessionManager *_dataSessionManager; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +@end | ||
| 24 | + | ||
| 25 | +@implementation HttpService | ||
| 26 | + | ||
| 27 | +#pragma mark - | ||
| 28 | +#pragma mark - SINGLETON | ||
| 29 | + | ||
| 30 | +static HttpService * __singleton__; | ||
| 31 | + | ||
| 32 | ++ (HttpService *)service { | ||
| 33 | + static dispatch_once_t predicate; | ||
| 34 | + dispatch_once( &predicate, ^{ __singleton__ = [[[self class] alloc] init]; } ); | ||
| 35 | + return __singleton__; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +#pragma mark - | ||
| 39 | +#pragma mark - Init | ||
| 40 | + | ||
| 41 | +- (instancetype)init { | ||
| 42 | + self = [super init]; | ||
| 43 | + if (self) { | ||
| 44 | + [self initManagers]; | ||
| 45 | + } | ||
| 46 | + return self; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +/** 所有网络请求的基础 */ | ||
| 50 | +- (NSURLSessionDataTask *)sendRequestWithHttpMethod:(HTTP_REQUEST_METHOD)method URLPath:(NSString *)pathStr parameters:(id)parameters isCache:(BOOL)isCache CheckParam:(NSArray *)checkParam completionHandler:(completionHandler)completionHandler | ||
| 51 | +{ | ||
| 52 | + CNLiveRequestMethod requestMethod = method == E_HTTP_REQUEST_METHOD_POST ? CNLiveRequestMethodPOST : CNLiveRequestMethodGET; | ||
| 53 | + CNLiveNetworkCacheType networkCacheType = isCache ? CNLiveNetworkCacheTypeCacheNetwork : CNLiveNetworkCacheTypeNetworkOnly; | ||
| 54 | + [CNLiveNetworking setupDome:NO]; | ||
| 55 | + [CNLiveNetworking setupShowDataResult:NO]; | ||
| 56 | + [CNLiveNetworking setAllowRequestDefaultArgument:YES]; | ||
| 57 | + return (NSURLSessionDataTask *)[CNLiveNetworking requestNetworkWithMethod:requestMethod URLString:pathStr Param:parameters==nil?@{}:parameters CacheType:networkCacheType CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | ||
| 58 | + NSDictionary * responseObjectDic = [responseObject mj_keyValues]; | ||
| 59 | + | ||
| 60 | + if (error) { | ||
| 61 | + if (completionHandler) completionHandler(responseObject, error); | ||
| 62 | + return; | ||
| 63 | + } | ||
| 64 | + NSString *resultCode = [NSString stringWithFormat:@"%@", responseObjectDic[errorCode]]; | ||
| 65 | + NSError *err = nil; | ||
| 66 | + id data = nil; | ||
| 67 | + if([resultCode isEqualToString:@"0"]) { | ||
| 68 | + data = responseObjectDic[requestData]; | ||
| 69 | + } else { | ||
| 70 | + @try { | ||
| 71 | + err = [[NSError alloc] initWithDomain:responseObjectDic[errorMessage] code:[resultCode integerValue] userInfo:nil]; | ||
| 72 | + } @catch (NSException *exception) { | ||
| 73 | + err = [[NSError alloc] initWithDomain:@"接口异常" code:500 userInfo:nil]; | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + if (completionHandler) completionHandler(data, err); | ||
| 77 | + }]; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +- (NSString *)stringWithMethod:(HTTP_REQUEST_METHOD)method { | ||
| 81 | + switch (method) { | ||
| 82 | + case E_HTTP_REQUEST_METHOD_GET: return @"GET"; break; | ||
| 83 | + case E_HTTP_REQUEST_METHOD_POST: return @"POST"; break; | ||
| 84 | + default: | ||
| 85 | + break; | ||
| 86 | + } | ||
| 87 | + return @""; | ||
| 88 | +} | ||
| 89 | +/** 清除所有任务 */ | ||
| 90 | +- (void)cleanAllTask { | ||
| 91 | + [self invalidateManagers]; | ||
| 92 | + [self initManagers]; | ||
| 93 | + [CNLiveNetworking cancelAll]; | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +- (void)invalidateManagers { | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +#pragma mark - | ||
| 100 | +#pragma mark - Ptavite Methods | ||
| 101 | +- (void)initManagers { | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +@end |
Example/CNLiveBusinessTools.xcodeproj/project.pbxproj
| @@ -346,23 +346,25 @@ | @@ -346,23 +346,25 @@ | ||
| 346 | buildActionMask = 2147483647; | 346 | buildActionMask = 2147483647; |
| 347 | files = ( | 347 | files = ( |
| 348 | ); | 348 | ); |
| 349 | - inputFileListPaths = ( | ||
| 350 | - ); | ||
| 351 | inputPaths = ( | 349 | inputPaths = ( |
| 352 | "${PODS_ROOT}/Target Support Files/Pods-CNLiveBusinessTools_Example/Pods-CNLiveBusinessTools_Example-frameworks.sh", | 350 | "${PODS_ROOT}/Target Support Files/Pods-CNLiveBusinessTools_Example/Pods-CNLiveBusinessTools_Example-frameworks.sh", |
| 351 | + "${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework", | ||
| 353 | "${BUILT_PRODUCTS_DIR}/CNLiveBaseKit/CNLiveBaseKit.framework", | 352 | "${BUILT_PRODUCTS_DIR}/CNLiveBaseKit/CNLiveBaseKit.framework", |
| 354 | "${BUILT_PRODUCTS_DIR}/CNLiveBusinessTools/CNLiveBusinessTools.framework", | 353 | "${BUILT_PRODUCTS_DIR}/CNLiveBusinessTools/CNLiveBusinessTools.framework", |
| 355 | "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", | 354 | "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", |
| 355 | + "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework", | ||
| 356 | + "${BUILT_PRODUCTS_DIR}/CNLiveTripartiteManagement/CNLiveTripartiteManagement.framework", | ||
| 356 | "${BUILT_PRODUCTS_DIR}/CNLiveUserManagement/CNLiveUserManagement.framework", | 357 | "${BUILT_PRODUCTS_DIR}/CNLiveUserManagement/CNLiveUserManagement.framework", |
| 357 | "${BUILT_PRODUCTS_DIR}/MJExtension/MJExtension.framework", | 358 | "${BUILT_PRODUCTS_DIR}/MJExtension/MJExtension.framework", |
| 358 | ); | 359 | ); |
| 359 | name = "[CP] Embed Pods Frameworks"; | 360 | name = "[CP] Embed Pods Frameworks"; |
| 360 | - outputFileListPaths = ( | ||
| 361 | - ); | ||
| 362 | outputPaths = ( | 361 | outputPaths = ( |
| 362 | + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework", | ||
| 363 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBaseKit.framework", | 363 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBaseKit.framework", |
| 364 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBusinessTools.framework", | 364 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBusinessTools.framework", |
| 365 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", | 365 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", |
| 366 | + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", | ||
| 367 | + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveTripartiteManagement.framework", | ||
| 366 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserManagement.framework", | 368 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserManagement.framework", |
| 367 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJExtension.framework", | 369 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJExtension.framework", |
| 368 | ); | 370 | ); |
Example/Podfile
| @@ -7,6 +7,12 @@ platform :ios, '9.0' | @@ -7,6 +7,12 @@ platform :ios, '9.0' | ||
| 7 | 7 | ||
| 8 | target 'CNLiveBusinessTools_Example' do | 8 | target 'CNLiveBusinessTools_Example' do |
| 9 | pod 'CNLiveBusinessTools', :path => '../' | 9 | pod 'CNLiveBusinessTools', :path => '../' |
| 10 | + | ||
| 11 | + pod 'CNLiveEnvironment' | ||
| 12 | + pod 'CNLiveUserManagement' | ||
| 13 | + pod 'CNLiveBaseKit' | ||
| 14 | + pod 'CNLiveRequestBastKit' | ||
| 15 | + | ||
| 10 | target 'CNLiveBusinessTools_Tests' do | 16 | target 'CNLiveBusinessTools_Tests' do |
| 11 | inherit! :search_paths | 17 | inherit! :search_paths |
| 12 | 18 |
README.md
| 1 | # CNLiveBusinessTools | 1 | # CNLiveBusinessTools |
| 2 | 2 | ||
| 3 | + | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + | ||
| 3 | [](https://travis-ci.org/郭瑞朋/CNLiveBusinessTools) | 7 | [](https://travis-ci.org/郭瑞朋/CNLiveBusinessTools) |
| 4 | [](https://cocoapods.org/pods/CNLiveBusinessTools) | 8 | [](https://cocoapods.org/pods/CNLiveBusinessTools) |
| 5 | [](https://cocoapods.org/pods/CNLiveBusinessTools) | 9 | [](https://cocoapods.org/pods/CNLiveBusinessTools) |