├── JCNetwork ├── Assets │ └── .gitkeep └── Classes │ ├── .gitkeep │ ├── Define │ ├── JCNetworkResponse.m │ ├── JCNetworkResponse.h │ └── JCNetworkDefine.h │ ├── Products │ ├── JCResponedObj.h │ ├── JCResponedObj.m │ ├── JCRequestObj.m │ ├── JCRequest.h │ ├── JCRequestObj.h │ └── JCRequest.m │ ├── Handle │ ├── DispatchElement.m │ ├── DispatchElement.h │ ├── JCCacheResponedDispatcher.h │ ├── JCDispatcher.h │ ├── JCRequester.h │ ├── JCCacheResponedDispatcher.m │ ├── JCRequester.m │ └── JCDispatcher.m │ ├── JCNetwork.h │ └── Service │ ├── JCRequestProxy.h │ └── JCRequestProxy.m ├── Example ├── Tests │ ├── en.lproj │ │ └── InfoPlist.strings │ ├── Tests-Prefix.pch │ ├── Tests-Info.plist │ └── Tests.m ├── JCNetwork │ ├── en.lproj │ │ └── InfoPlist.strings │ ├── JCViewController.h │ ├── JCAppDelegate.h │ ├── main.m │ ├── JCNetwork-Prefix.pch │ ├── JCViewController.m │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── LaunchImage.launchimage │ │ │ └── Contents.json │ ├── JCNetwork-Info.plist │ ├── LaunchScreen.storyboard │ ├── Main.storyboard │ └── JCAppDelegate.m ├── JCNetwork.xcodeproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── JCNetwork-Example.xcscheme │ └── project.pbxproj ├── Podfile └── JCNetwork.xcworkspace │ └── contents.xcworkspacedata ├── README.md ├── .gitignore ├── LICENSE └── JCNetwork.podspec /JCNetwork/Assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /JCNetwork/Classes/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Example/Tests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Example/JCNetwork/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JCNetwork 2 | 1、底层网络使用NSURLSession 3 | 4 | 2、json转对象使用YYModel 感谢 https://github.com/ibireme 5 | 6 | 3、封装成framwork方便调用 7 | -------------------------------------------------------------------------------- /Example/Tests/Tests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // The contents of this file are implicitly included at the beginning of every test case source file. 2 | 3 | #ifdef __OBJC__ 4 | 5 | @import Specta; 6 | @import Expecta; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Example/JCNetwork.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/JCNetwork/JCViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCViewController.h 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 11/27/2016. 6 | // Copyright (c) 2016 贾淼. All rights reserved. 7 | // 8 | 9 | @import UIKit; 10 | 11 | @interface JCViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/SerilesJam/Specs.git' 2 | 3 | use_frameworks! 4 | 5 | target 'JCNetwork_Example' do 6 | pod 'JCNetwork', :path => '../' 7 | 8 | target 'JCNetwork_Tests' do 9 | inherit! :search_paths 10 | 11 | pod 'Specta' 12 | pod 'Expecta' 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /Example/JCNetwork.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/JCNetwork/JCAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCAppDelegate.h 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 11/27/2016. 6 | // Copyright (c) 2016 贾淼. All rights reserved. 7 | // 8 | 9 | @import UIKit; 10 | 11 | @interface JCAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Example/JCNetwork/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 11/27/2016. 6 | // Copyright (c) 2016 贾淼. All rights reserved. 7 | // 8 | 9 | @import UIKit; 10 | #import "JCAppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) 13 | { 14 | @autoreleasepool { 15 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([JCAppDelegate class])); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Example/JCNetwork/JCNetwork-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | @import UIKit; 15 | @import Foundation; 16 | #endif 17 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Define/JCNetworkResponse.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCNetworkResponse.m 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-23. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCNetworkResponse.h" 10 | 11 | @implementation JCNetworkResponse 12 | 13 | @synthesize requestID; 14 | @synthesize status; 15 | @synthesize progress; 16 | @synthesize content; 17 | @synthesize error; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Products/JCResponedObj.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCResponedObject.h 3 | // JCNetwork 4 | // 5 | // Created by Jam on 16/1/5. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JCResponedObj : NSObject 12 | 13 | + (instancetype)modelWithDictionary:(NSDictionary *)dictionary; 14 | 15 | + (NSDictionary *)modelCustomPropertyMapper; 16 | + (NSDictionary *)modelContainerPropertyGenericClass; 17 | 18 | - (id)modelToJSONObject; 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/DispatchElement.m: -------------------------------------------------------------------------------- 1 | // 2 | // DispatchElement.m 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-23. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "DispatchElement.h" 10 | 11 | @implementation DispatchElement 12 | 13 | @synthesize requestID = _requestID; 14 | @synthesize responseBlock = _responseBlock; 15 | @synthesize entityClassName = _entityClassName; 16 | @synthesize request = _request; 17 | 18 | 19 | - (id)init { 20 | self = [super init]; 21 | 22 | if (self) { 23 | } 24 | 25 | return self; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/DispatchElement.h: -------------------------------------------------------------------------------- 1 | // 2 | // DispatchElement.h 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-23. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCRequest.h" 10 | #import "JCNetworkResponse.h" 11 | 12 | @interface DispatchElement : NSObject 13 | 14 | @property (nonatomic, assign) JCRequestID requestID; 15 | @property (nonatomic, copy) void (^responseBlock)(JCNetworkResponse *response); 16 | @property (nonatomic, strong) JCRequest *request; 17 | @property (nonatomic, strong) NSString *entityClassName; 18 | 19 | 20 | - (id)init; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Example/JCNetwork/JCViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCViewController.m 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 11/27/2016. 6 | // Copyright (c) 2016 贾淼. All rights reserved. 7 | // 8 | 9 | #import "JCViewController.h" 10 | 11 | @interface JCViewController () 12 | 13 | @end 14 | 15 | @implementation JCViewController 16 | 17 | - (void)viewDidLoad 18 | { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | 23 | - (void)didReceiveMemoryWarning 24 | { 25 | [super didReceiveMemoryWarning]; 26 | // Dispose of any resources that can be recreated. 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Products/JCResponedObj.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCResponedObject.m 3 | // JCNetwork 4 | // 5 | // Created by Jam on 16/1/5. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCResponedObj.h" 10 | 11 | @implementation JCResponedObj 12 | 13 | + (instancetype)modelWithDictionary:(NSDictionary *)dictionary { 14 | return [self yy_modelWithDictionary:dictionary]; 15 | } 16 | 17 | + (NSDictionary *)modelCustomPropertyMapper { 18 | return nil; 19 | } 20 | 21 | + (NSDictionary *)modelContainerPropertyGenericClass { 22 | return nil; 23 | } 24 | 25 | - (id)modelToJSONObject { 26 | return [self yy_modelToJSONObject]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Define/JCNetworkResponse.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCNetworkResponse.h 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-23. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCNetworkDefine.h" 10 | 11 | @interface JCNetworkResponse : NSObject 12 | 13 | @property (nonatomic, assign) JCRequestID requestID; //请求ID 14 | @property (nonatomic, assign) JCNetworkResponseStatus status; //请求响应状态 15 | @property (nonatomic, assign) CGFloat progress; //上传下载进度 16 | @property (nonatomic, strong) NSError *error; //请求响应错误原因 17 | @property (nonatomic, strong) id content; //请求响应返回json内容 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/JCCacheResponedDispatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCCacheResponedDispatcher.h 3 | // JCNetwork 4 | // 5 | // Created by seris-Jam on 16/8/27. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JCCacheResponed : NSObject 12 | 13 | //时间戳 14 | @property (nonatomic, assign) NSTimeInterval timeInterval; 15 | @property (nonatomic, strong) NSDictionary *responedDic; 16 | 17 | @end 18 | 19 | @interface JCCacheResponedDispatcher : NSObject 20 | 21 | + (id)sharedInstance; 22 | 23 | - (void)saveCacheResponed:(NSDictionary *)responedDic forKey:(NSString *)cacheKey; 24 | - (JCCacheResponed *)getCacheResponedWithKey:(NSString *)cacheKey; 25 | - (void)clearn; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /JCNetwork/Classes/JCNetwork.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCNetwork.h 3 | // JCNetwork 4 | // 5 | // Created by Jam on 16/1/5. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #if __has_include() 12 | FOUNDATION_EXPORT double JCNetworkVersionNumber; 13 | FOUNDATION_EXPORT const unsigned char JCNetworkVersionString[]; 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #else 20 | #import "JCNetworkDefine.h" 21 | #import "JCNetworkResponse.h" 22 | #import "JCRequestProxy.h" 23 | #import "JCRequestObj.h" 24 | #import "JCResponedObj.h" 25 | #endif 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Example/Tests/Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | Carthage 26 | # We recommend against adding the Pods directory to your .gitignore. However 27 | # you should judge for yourself, the pros and cons are mentioned at: 28 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 29 | # 30 | # Note: if you ignore the Pods directory, make sure to uncomment 31 | # `pod install` in .travis.yml 32 | # 33 | # Pods/ 34 | *.lock 35 | Example/Pods 36 | _Pods.xcodeproj 37 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Products/JCRequestObj.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequestObj.m 3 | // JCNetwork 4 | // 5 | // Created by Jam on 14-7-14. 6 | // Copyright (c) 2014年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCRequestObj.h" 10 | 11 | @implementation JCRequestObj 12 | 13 | @synthesize hostName = _hostName; 14 | @synthesize path = _path; 15 | 16 | - (id)init { 17 | self = [super init]; 18 | 19 | if (self) { 20 | self.parameterType = JCNetworkParameterTypeURL; 21 | self.timeoutInterval = 60.0; 22 | 23 | self.cachePolicy = JCNetWorkReloadIgnoringLocalCacheData; 24 | self.cacheRefreshTimeInterval = 24*60*60; 25 | } 26 | return self; 27 | } 28 | 29 | - (NSDictionary *)handlerParamsDic:(NSDictionary *)orginParamsDic { 30 | return orginParamsDic; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/JCDispatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCDispatcher.h 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-21. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "DispatchElement.h" 11 | 12 | @interface JCDispatcher : NSObject { 13 | @package 14 | NSMutableDictionary *_serviceDict; 15 | NSMutableDictionary *_dispatchTable; 16 | } 17 | 18 | @property (nonatomic, readonly) NSMutableDictionary *serviceDict; 19 | 20 | + (id)sharedInstance; 21 | - (id)init; 22 | 23 | - (void)addGetDispatchItem:(DispatchElement *)item; 24 | - (void)addPostDispatchItem:(DispatchElement *)item; 25 | - (void)addDispatchUploadItem:(DispatchElement *)item withFiles:(NSDictionary *)files; 26 | - (void)addDispatchDownloadItem:(DispatchElement *)item; 27 | 28 | - (void)cancelRequest:(JCRequestID)requestID; 29 | - (void)cancelAllRequest; 30 | 31 | - (void)dispatchResponse:(JCNetworkResponse *)response forElement:(DispatchElement *)element; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Products/JCRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequest.h 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 16/7/20. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCNetworkDefine.h" 10 | #import "JCRequestObj.h" 11 | 12 | //内部请求类,主要用来保存内部请求参数等 13 | 14 | @interface JCRequest : NSObject 15 | 16 | @property (nonatomic, readonly, strong) NSString *URLString; 17 | @property (nonatomic, readonly, strong) NSDictionary *paramsDic; 18 | @property (nonatomic, readonly, strong) NSDictionary *headerFieldDic; 19 | @property (nonatomic, assign) NSTimeInterval timeoutInterval; 20 | 21 | //缓存key 22 | @property (nonatomic, readonly, strong) NSString *cacheKey; 23 | 24 | @property (nonatomic, assign) JCRequestCachePolicy cachePolicy; 25 | @property (nonatomic, assign) NSTimeInterval cacheRefreshTimeInterval; 26 | 27 | @property (nonatomic, readonly, strong) AFHTTPRequestSerializer *requestSerializer; 28 | 29 | - (instancetype)initWithRequestObj:(JCRequestObj *)requestObj; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Example/Tests/Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCNetworkTests.m 3 | // JCNetworkTests 4 | // 5 | // Created by 贾淼 on 11/27/2016. 6 | // Copyright (c) 2016 贾淼. All rights reserved. 7 | // 8 | 9 | // https://github.com/Specta/Specta 10 | 11 | SpecBegin(InitialSpecs) 12 | 13 | describe(@"these will fail", ^{ 14 | 15 | it(@"can do maths", ^{ 16 | expect(1).to.equal(2); 17 | }); 18 | 19 | it(@"can read", ^{ 20 | expect(@"number").to.equal(@"string"); 21 | }); 22 | 23 | it(@"will wait for 10 seconds and fail", ^{ 24 | waitUntil(^(DoneCallback done) { 25 | 26 | }); 27 | }); 28 | }); 29 | 30 | describe(@"these will pass", ^{ 31 | 32 | it(@"can do maths", ^{ 33 | expect(1).beLessThan(23); 34 | }); 35 | 36 | it(@"can read", ^{ 37 | expect(@"team").toNot.contain(@"I"); 38 | }); 39 | 40 | it(@"will wait and succeed", ^{ 41 | waitUntil(^(DoneCallback done) { 42 | done(); 43 | }); 44 | }); 45 | }); 46 | 47 | SpecEnd 48 | 49 | -------------------------------------------------------------------------------- /Example/JCNetwork/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Products/JCRequestObj.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequestObj.h 3 | // JCNetwork 4 | // 5 | // Created by Jam on 14-7-14. 6 | // Copyright (c) 2014年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCNetworkDefine.h" 10 | 11 | @interface JCRequestObj : NSObject 12 | 13 | @property (assign, nonatomic) JCNetworkParameterType parameterType; 14 | @property (strong, nonatomic) NSString *hostName; 15 | @property (strong, nonatomic) NSString *path; 16 | @property (nonatomic, assign) NSTimeInterval timeoutInterval; 17 | 18 | //headerfield 19 | @property (nonatomic, strong) NSDictionary *headerFieldDic; 20 | //直接采用NSDictionary作为请求参数 21 | @property (nonatomic, strong) NSDictionary *paramsDic; 22 | 23 | //缓存key,默认为绝对URL地址,可以自己修改 24 | @property (nonatomic, strong) NSString *cacheKey; 25 | 26 | @property (nonatomic, assign) JCRequestCachePolicy cachePolicy; 27 | //在JCNetWorkReturnCacheDataReLoad 模式下,缓存多长时间要刷新,其他模式都没用, 默认缓存一天, 单位为秒 28 | @property (nonatomic, assign) NSTimeInterval cacheRefreshTimeInterval; 29 | 30 | //处理请求参数,默认不处理,子类可对改参数做额外修改 31 | - (NSDictionary *)handlerParamsDic:(NSDictionary *)orginParamsDic; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 贾淼 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Define/JCNetworkDefine.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCNetworkDefine.h 3 | // JCNetwork 4 | // 5 | // Created by Jam on 13-6-23. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #ifndef JCNetwork_JCNetworkDefine_h 10 | #define JCNetwork_JCNetworkDefine_h 11 | 12 | //定义JCRequestID类型用于记录每次请求的ID 13 | typedef unsigned int JCRequestID; 14 | 15 | //错误的请求ID 对应的serviceID不存在或者是请求的methodName不存在 16 | #define JC_ERROR_REQUESTID 0 17 | 18 | //请求响应的状态 19 | typedef NS_ENUM (NSInteger, JCNetworkResponseStatus) { 20 | JCNetworkResponseStatusSuccess, 21 | JCNetworkResponseStatusDowning, 22 | JCNetworkResponseStatusUploading, 23 | JCNetworkResponseStatusFailed 24 | }; 25 | 26 | //请求发送格式 27 | typedef NS_ENUM (NSInteger, JCNetworkParameterType) { 28 | JCNetworkParameterTypeURL = 0, 29 | JCNetworkParameterTypeJSON = 1, 30 | JCNetworkParameterTypeList = 2 31 | }; 32 | 33 | //缓存状态设定 34 | typedef NS_ENUM(NSUInteger, JCRequestCachePolicy){ 35 | JCNetWorkReloadIgnoringLocalCacheData, ///忽略缓存,重新请求 36 | //一下二种情况,当网络请求失败时都会返回数据 37 | JCNetWorkReturnCacheDataElseLoad, ///有缓存就用缓存,没有缓存就重新请求(用于数据不变时) 38 | JCNetWorkReturnCacheDataReLoad, ///设置一个缓存时间,如果超过缓存存储时间就重新请求并缓存,如果在缓存时间内则返回缓存内容 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Example/JCNetwork/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/JCRequester.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequester.h 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-20. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCNetworkResponse.h" 10 | #import "JCDispatcher.h" 11 | 12 | #define JC_MIN_REQUESTID 1 13 | #define JC_MAX_REQUESTID UINT_MAX 14 | 15 | 16 | @interface JCRequester : NSObject { 17 | @package 18 | NSMutableDictionary *_requestEngines; 19 | JCRequestID _lastRequestID; 20 | JCDispatcher *_dispatcher; 21 | } 22 | 23 | + (id)sharedInstance; 24 | - (id)init; 25 | 26 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(void (^)(JCNetworkResponse *response))responedBlock; 27 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(void (^)(JCNetworkResponse *response))responedBlock; 28 | 29 | //upload request 30 | - (JCRequestID)upLoadFileWithRequest:(JCRequestObj *)requestObj files:(NSDictionary *)files entityClass:(NSString *)entityName withUpLoadBlock:(void (^)(JCNetworkResponse *response))upLoadBlock; 31 | 32 | //download request 33 | - (JCRequestID)downLoadFileFrom:(NSURL *)remoteURL toFile:(NSString*)filePath withDownLoadBlock:(void (^)(JCNetworkResponse *response))responedBlock; 34 | 35 | //image request 36 | - (void)autoLoadImageWithURL:(NSURL *)imageURL placeHolderImage:(UIImage*)image toImageView:(UIImageView *)imageView; 37 | - (void)loadImageWithURL:(NSURL *)imageURL completionHandler:(void (^)(UIImage *fetchImage, BOOL isCache))imageFetchBlock; 38 | - (UIImage *)getImageIfExisted:(NSURL *)imageURL; 39 | 40 | //cancelRequest with RequestID 41 | - (void)cancelRequest:(JCRequestID)requestID; 42 | - (void)cancelAllRequest; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Example/JCNetwork/JCNetwork-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Example/JCNetwork/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Example/JCNetwork/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Example/JCNetwork/JCAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCAppDelegate.m 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 11/27/2016. 6 | // Copyright (c) 2016 贾淼. All rights reserved. 7 | // 8 | 9 | #import "JCAppDelegate.h" 10 | 11 | @implementation JCAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/JCCacheResponedDispatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCCacheResponedDispatcher.m 3 | // JCNetwork 4 | // 5 | // Created by seris-Jam on 16/8/27. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCCacheResponedDispatcher.h" 10 | 11 | @implementation JCCacheResponed 12 | 13 | - (instancetype)init { 14 | self = [super init]; 15 | 16 | if (self) { 17 | } 18 | 19 | return self; 20 | } 21 | 22 | - (void)encodeWithCoder:(NSCoder *)aCoder { 23 | [aCoder encodeObject:[NSNumber numberWithDouble:_timeInterval] forKey:@"timeInterval"]; 24 | [aCoder encodeObject:_responedDic forKey:@"responedDic"]; 25 | } 26 | 27 | - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { 28 | if (self = [super init]) { 29 | self.timeInterval = [[aDecoder decodeObjectForKey:@"timeInterval"] doubleValue]; 30 | self.responedDic = [aDecoder decodeObjectForKey:@"responedDic"]; 31 | } 32 | return self; 33 | } 34 | 35 | @end 36 | 37 | 38 | @interface JCCacheResponedDispatcher () 39 | 40 | @property (nonatomic, strong) YYCache *cache; 41 | 42 | @end 43 | 44 | @implementation JCCacheResponedDispatcher 45 | 46 | + (id)sharedInstance { 47 | static dispatch_once_t pred; 48 | static JCCacheResponedDispatcher *sharedInstance = nil; 49 | dispatch_once(&pred, ^{ 50 | sharedInstance = [[JCCacheResponedDispatcher alloc] init]; 51 | }); 52 | return sharedInstance; 53 | } 54 | 55 | - (id)init { 56 | self = [super init]; 57 | 58 | if (self) { 59 | self.cache = [[YYCache alloc] initWithName:@"JCNetworkCache"]; 60 | self.cache.memoryCache.shouldRemoveAllObjectsOnMemoryWarning = YES; 61 | self.cache.memoryCache.shouldRemoveAllObjectsWhenEnteringBackground = YES; 62 | 63 | } 64 | return self; 65 | } 66 | 67 | - (void)saveCacheResponed:(NSDictionary *)responedDic forKey:(NSString *)cacheKey { 68 | JCCacheResponed *cacheResponed = [[JCCacheResponed alloc] init]; 69 | cacheResponed.timeInterval = [[NSDate date] timeIntervalSince1970]; 70 | cacheResponed.responedDic = responedDic; 71 | 72 | [self.cache setObject:cacheResponed forKey:cacheKey]; 73 | } 74 | 75 | - (JCCacheResponed *)getCacheResponedWithKey:(NSString *)cacheKey { 76 | return [self.cache objectForKey:cacheKey]; 77 | } 78 | 79 | - (void)clearn { 80 | [self.cache removeAllObjects]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Service/JCRequestProxy.h: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequestProxy.h 3 | // JCNetwork 4 | // 5 | // Created by Jam on 16/1/5. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCNetworkResponse.h" 10 | #import "JCRequestObj.h" 11 | #import "JCResponedObj.h" 12 | 13 | typedef void(^JCNetworkResponseBlock)(JCNetworkResponse *response); 14 | typedef void(^JCNetworkImageFetch)(UIImage *fetchImage, BOOL isCache); 15 | 16 | @interface JCRequestProxy : NSObject 17 | 18 | + (instancetype)sharedInstance; 19 | 20 | - (instancetype)init; 21 | 22 | // Get Request 23 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(JCNetworkResponseBlock)responedBlock; 24 | 25 | // Get Request with Control 26 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withCompleteBlock:(JCNetworkResponseBlock)responedBlock; 27 | 28 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withSucessBlock:(void (^)(id content))sucessBlock andFailedBlock:(void (^)(NSError *error))failedBlock; 29 | 30 | //Post Request 31 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(JCNetworkResponseBlock)responedBlock; 32 | 33 | //Post Request with Control 34 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withCompleteBlock:(JCNetworkResponseBlock)responedBlock; 35 | 36 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withSucessBlock:(void (^)(id content))sucessBlock andFailedBlock:(void (^)(NSError *error))failedBlock; 37 | 38 | //upload 39 | - (JCRequestID)upLoadFileWithRequest:(JCRequestObj *)requestObj files:(NSDictionary *)files entityClass:(NSString *)entityName withUpLoadBlock:(JCNetworkResponseBlock)responedBlock; 40 | 41 | //download 42 | - (JCRequestID)downLoadFileFrom:(NSURL *)remoteURL toFile:(NSString*)filePath withDownLoadBlock:(JCNetworkResponseBlock)responedBlock; 43 | 44 | - (__kindof JCResponedObj *)getCacheResponedObj:(JCRequestObj *)requestObj entityClass:(NSString *)entityName; 45 | 46 | //Image请求 47 | - (void)autoLoadImageWithURL:(NSURL *)imageURL placeHolderImage:(UIImage*)image toImageView:(UIImageView *)imageView; 48 | - (void)loadImageWithURL:(NSURL *)imageURL completionHandler:(JCNetworkImageFetch)imageFetchBlock; 49 | - (UIImage *)getImageIfExisted:(NSURL *)imageURL; 50 | 51 | // 根据请求ID取消一个请求 52 | - (void)cancelRequestID:(JCRequestID)requestID; 53 | - (void)cancelAllRequest; 54 | 55 | //清除缓存 56 | - (void)clearSave; 57 | @end 58 | -------------------------------------------------------------------------------- /JCNetwork.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint JCNetwork.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'JCNetwork' 11 | s.version = '1.0' 12 | s.summary = 'JCNetwork是一套基于AFNetworking实现的http网络请求' 13 | 14 | # This description is used to generate tags and improve search results. 15 | # * Think: What does it do? Why did you write it? What is the focus? 16 | # * Try to keep it short, snappy and to the point. 17 | # * Write the description between the DESC delimiters below. 18 | # * Finally, don't worry about the indent, CocoaPods strips it! 19 | 20 | s.description = <<-DESC 21 | JCNetwork是一套基于AFNetworking实现的http网络请求,使用YYMolde解析json格式 22 | DESC 23 | 24 | s.homepage = 'https://github.com/SerilesJam/JCNetwork' 25 | s.license = { :type => 'MIT', :file => 'LICENSE' } 26 | s.author = { '贾淼' => 'hxjiamiao@126.com' } 27 | s.source = { :git => 'https://github.com/SerilesJam/JCNetwork.git', :tag => s.version.to_s } 28 | # s.social_media_url = 'https://twitter.com/' 29 | 30 | s.ios.deployment_target = '7.0' 31 | 32 | s.source_files = 'JCNetwork/Classes/JCNetwork.h' 33 | s.public_header_files = 'JCNetwork/Classes/JCNetwork.h' 34 | 35 | pch_JCNetwork = <<-EOS 36 | #import "AFNetworking.h" 37 | #import "NSObject+YYModel.h" 38 | #import "YYCache.h" 39 | #import "Aspects.h" 40 | EOS 41 | s.prefix_header_contents = pch_JCNetwork 42 | 43 | s.subspec 'Define' do |ss| 44 | ss.source_files = 'JCNetwork/Classes/Define/*' 45 | ss.public_header_files = 'JCNetwork/Classes/Define/*.h' 46 | end 47 | 48 | s.subspec 'Products' do |ss| 49 | ss.source_files = 'JCNetwork/Classes/Products/*' 50 | ss.public_header_files = 'JCNetwork/Classes/Products/JC{Request,Responed}Obj.h' 51 | 52 | ss.dependency 'JCNetwork/Define' 53 | end 54 | 55 | s.subspec 'Handle' do |ss| 56 | ss.source_files = 'JCNetwork/Classes/Handle/*' 57 | ss.private_header_files = 'JCNetwork/Classes/Handle/*.h' 58 | 59 | ss.dependency 'JCNetwork/Products' 60 | end 61 | 62 | s.subspec 'Service' do |ss| 63 | ss.source_files = 'JCNetwork/Classes/Service/*' 64 | ss.public_header_files = 'JCNetwork/Classes/Service/JCRequestProxy.h' 65 | 66 | ss.dependency 'JCNetwork/Handle' 67 | end 68 | 69 | s.frameworks = 'UIKit', 'ImageIO', 'Security', 'CFNetwork', 'SystemConfiguration' 70 | s.dependency 'AFNetworking' 71 | s.dependency 'YYModel' 72 | s.dependency 'YYCache' 73 | s.dependency 'Aspects' 74 | s.dependency 'SDWebImage' 75 | 76 | end 77 | -------------------------------------------------------------------------------- /Example/JCNetwork.xcodeproj/xcshareddata/xcschemes/JCNetwork-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Products/JCRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequest.m 3 | // JCNetwork 4 | // 5 | // Created by 贾淼 on 16/7/20. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCRequest.h" 10 | 11 | @implementation JCRequest 12 | 13 | - (instancetype)init { 14 | self = [super init]; 15 | 16 | if (self) { 17 | 18 | } 19 | 20 | return self; 21 | } 22 | 23 | - (instancetype)initWithRequestObj:(JCRequestObj *)requestObj { 24 | self = [super init]; 25 | 26 | if (self) { 27 | _paramsDic = [self bulidRequestParamsWithRequest:requestObj]; 28 | _headerFieldDic = requestObj.headerFieldDic; 29 | _URLString = [self getURLStringWithRequest:requestObj]; 30 | _requestSerializer = [self getRequestSerializeWithRequest:requestObj]; 31 | _timeoutInterval = requestObj.timeoutInterval; 32 | 33 | if (requestObj.cacheKey) { 34 | _cacheKey = requestObj.cacheKey; 35 | } else { 36 | _cacheKey = [self getAbsoluteURLStringWithPath:_URLString withParameters:_paramsDic]; 37 | } 38 | 39 | _cachePolicy = requestObj.cachePolicy; 40 | _cacheRefreshTimeInterval = requestObj.cacheRefreshTimeInterval; 41 | } 42 | 43 | return self; 44 | } 45 | 46 | #pragma mark private method 47 | 48 | - (NSDictionary *)bulidRequestParamsWithRequest:(JCRequestObj *)requestObj { 49 | 50 | if (requestObj.paramsDic) { 51 | return requestObj.paramsDic; 52 | } 53 | 54 | NSMutableDictionary *paramsDict = [NSMutableDictionary dictionaryWithDictionary:[requestObj yy_modelToJSONObject]]; 55 | //删除不必要的属性 56 | [paramsDict removeObjectForKey:@"hostName"]; 57 | [paramsDict removeObjectForKey:@"path"]; 58 | [paramsDict removeObjectForKey:@"parameterType"]; 59 | [paramsDict removeObjectForKey:@"timeoutInterval"]; 60 | [paramsDict removeObjectForKey:@"cachePolicy"]; 61 | [paramsDict removeObjectForKey:@"cacheRefreshTimeInterval"]; 62 | [paramsDict removeObjectForKey:@"cacheKey"]; 63 | [paramsDict removeObjectForKey:@"headerFieldDic"]; 64 | [paramsDict removeObjectForKey:@"paramsDic"]; 65 | paramsDict = [NSMutableDictionary dictionaryWithDictionary:[requestObj handlerParamsDic:paramsDict]]; 66 | 67 | return paramsDict; 68 | } 69 | 70 | - (NSString *)getURLStringWithRequest:(JCRequestObj *)requestObj { 71 | 72 | NSMutableString *urlString = [NSMutableString stringWithString:requestObj.hostName]; 73 | 74 | if ([urlString characterAtIndex:[urlString length]-1] == '/') { 75 | urlString = [NSMutableString stringWithString:[urlString substringToIndex:[urlString length]-1]]; 76 | } 77 | 78 | if(requestObj.path) { 79 | if(requestObj.path.length > 0 && [requestObj.path characterAtIndex:0] == '/') 80 | [urlString appendFormat:@"%@", requestObj.path]; 81 | else if (requestObj.path != nil) 82 | [urlString appendFormat:@"/%@", requestObj.path]; 83 | } 84 | return urlString; 85 | } 86 | 87 | - (NSString *)getAbsoluteURLStringWithPath:(NSString *)urlString withParameters:(NSDictionary *)parameters { 88 | 89 | if (parameters) { 90 | if (![NSJSONSerialization isValidJSONObject:parameters]) return nil; 91 | NSData *data = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:nil]; 92 | NSString *paramStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 93 | return [urlString stringByAppendingString:paramStr]; 94 | } 95 | 96 | return urlString; 97 | } 98 | 99 | - (AFHTTPRequestSerializer *)getRequestSerializeWithRequest:(JCRequestObj *)requestObj { 100 | AFHTTPRequestSerializer *requestSerializer; 101 | switch (requestObj.parameterType) { 102 | case JCNetworkParameterTypeURL: 103 | requestSerializer = [AFHTTPRequestSerializer serializer]; 104 | break; 105 | case JCNetworkParameterTypeJSON: 106 | requestSerializer = [AFJSONRequestSerializer serializer]; 107 | break; 108 | case JCNetworkParameterTypeList: 109 | requestSerializer = [AFPropertyListRequestSerializer serializer]; 110 | break; 111 | default: 112 | break; 113 | } 114 | 115 | for (NSString *key in [_headerFieldDic allKeys]) { 116 | [requestSerializer setValue:[_headerFieldDic objectForKey:key] forHTTPHeaderField:key]; 117 | } 118 | return requestSerializer; 119 | } 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/JCRequester.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequester.m 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-20. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCRequester.h" 10 | #import "DispatchElement.h" 11 | 12 | #import "AFNetworking.h" 13 | #import "AFImageDownloader.h" 14 | #import "UIImageView+AFNetworking.h" 15 | 16 | @implementation JCRequester 17 | 18 | + (id)sharedInstance 19 | { 20 | static dispatch_once_t pred; 21 | static JCRequester *sharedInstance = nil; 22 | dispatch_once(&pred, ^{ 23 | sharedInstance = [[JCRequester alloc] init]; 24 | }); 25 | return sharedInstance; 26 | } 27 | 28 | - (id)init 29 | { 30 | self = [super init]; 31 | 32 | if (self) { 33 | _requestEngines = [[NSMutableDictionary alloc] init]; 34 | _dispatcher = [JCDispatcher sharedInstance]; 35 | 36 | _lastRequestID = JC_MIN_REQUESTID; 37 | } 38 | 39 | return self; 40 | } 41 | 42 | #pragma mark request block 43 | 44 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(void (^)(JCNetworkResponse *response))responedBlock { 45 | if (++_lastRequestID >= JC_MAX_REQUESTID) { 46 | _lastRequestID = JC_MIN_REQUESTID; 47 | } 48 | 49 | JCRequest *request = [[JCRequest alloc] initWithRequestObj:requestObj]; 50 | DispatchElement *element = [self getDispatchElementWithCompleteBlock:responedBlock WithRequest:request entityClass:entityName]; 51 | [_dispatcher addGetDispatchItem:element]; 52 | 53 | return _lastRequestID; 54 | } 55 | 56 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(void (^)(JCNetworkResponse *response))responedBlock { 57 | if (++_lastRequestID >= JC_MAX_REQUESTID) { 58 | _lastRequestID = JC_MIN_REQUESTID; 59 | } 60 | 61 | JCRequest *request = [[JCRequest alloc] initWithRequestObj:requestObj]; 62 | DispatchElement *element = [self getDispatchElementWithCompleteBlock:responedBlock WithRequest:request entityClass:entityName]; 63 | [_dispatcher addPostDispatchItem:element]; 64 | 65 | return _lastRequestID; 66 | } 67 | 68 | #pragma mark upload request 69 | - (JCRequestID)upLoadFileWithRequest:(JCRequestObj *)requestObj files:(NSDictionary *)files entityClass:(NSString *)entityName withUpLoadBlock:(void (^)(JCNetworkResponse *response))upLoadBlock { 70 | if (++_lastRequestID >= JC_MAX_REQUESTID) { 71 | _lastRequestID = JC_MIN_REQUESTID; 72 | } 73 | JCRequest *request = [[JCRequest alloc] initWithRequestObj:requestObj]; 74 | DispatchElement *element = [self getDispatchElementWithCompleteBlock:upLoadBlock WithRequest:request entityClass:entityName]; 75 | [_dispatcher addDispatchUploadItem:element withFiles:files]; 76 | return _lastRequestID; 77 | } 78 | 79 | #pragma mark download request 80 | - (JCRequestID)downLoadFileFrom:(NSURL *)remoteURL toFile:(NSString*)filePath withDownLoadBlock:(void (^)(JCNetworkResponse *response))responedBlock { 81 | if (++_lastRequestID >= JC_MAX_REQUESTID) { 82 | _lastRequestID = JC_MIN_REQUESTID; 83 | } 84 | 85 | return _lastRequestID; 86 | } 87 | 88 | //image request 89 | - (void)autoLoadImageWithURL:(NSURL *)imageURL placeHolderImage:(UIImage*)image toImageView:(UIImageView *)imageView { 90 | [imageView setImageWithURL:imageURL placeholderImage:image]; 91 | } 92 | 93 | - (void)loadImageWithURL:(NSURL *)imageURL completionHandler:(void (^)(UIImage *fetchImage, BOOL isCache))imageFetchBlock { 94 | UIImage *cachedImage = [self getImageIfExisted:imageURL]; 95 | 96 | if (cachedImage) { 97 | imageFetchBlock(cachedImage, YES); 98 | return ; 99 | } 100 | AFImageDownloader *downloader = [AFImageDownloader defaultInstance]; 101 | NSMutableURLRequest *imageURLRequest = [NSMutableURLRequest requestWithURL:imageURL]; 102 | [imageURLRequest addValue:@"image/*" forHTTPHeaderField:@"Accept"]; 103 | [downloader downloadImageForURLRequest:imageURLRequest success:^(NSURLRequest * request, NSHTTPURLResponse * responed, UIImage * image){ 104 | imageFetchBlock(image, NO); 105 | } failure:^(NSURLRequest * request, NSHTTPURLResponse * responed, NSError * error){ 106 | imageFetchBlock(nil, NO); 107 | }]; 108 | } 109 | 110 | - (UIImage *)getImageIfExisted:(NSURL *)imageURL { 111 | 112 | AFImageDownloader *downloader = [AFImageDownloader defaultInstance]; 113 | id imageCache = downloader.imageCache; 114 | NSMutableURLRequest *imageURLRequest = [NSMutableURLRequest requestWithURL:imageURL]; 115 | [imageURLRequest addValue:@"image/*" forHTTPHeaderField:@"Accept"]; 116 | UIImage *cachedImage = [imageCache imageforRequest:imageURLRequest withAdditionalIdentifier:nil]; 117 | 118 | if (cachedImage) { 119 | return cachedImage; 120 | } 121 | 122 | return nil; 123 | } 124 | 125 | #pragma cancelRequest 126 | 127 | - (void)cancelRequest:(JCRequestID)requestID { 128 | [_dispatcher cancelRequest:requestID]; 129 | } 130 | 131 | - (void)cancelAllRequest { 132 | [_dispatcher cancelAllRequest]; 133 | } 134 | 135 | #pragma mark bulid DispatchElement 136 | 137 | - (DispatchElement *)getDispatchElementWithCompleteBlock:(void (^)(JCNetworkResponse *response))responedBlock WithRequest:(JCRequest *)request entityClass:(NSString *)entityName { 138 | 139 | DispatchElement *element = [[DispatchElement alloc] init]; 140 | element.requestID = _lastRequestID; 141 | element.responseBlock = responedBlock; 142 | element.entityClassName = entityName; 143 | element.request = request; 144 | 145 | return element; 146 | } 147 | 148 | @end 149 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Service/JCRequestProxy.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCRequestProxy.m 3 | // JCNetwork 4 | // 5 | // Created by Jam on 16/1/5. 6 | // Copyright © 2016年 Jam. All rights reserved. 7 | 8 | #import "JCRequestProxy.h" 9 | #import "JCRequester.h" 10 | #import "JCCacheResponedDispatcher.h" 11 | 12 | #import 13 | 14 | @interface JCRequestProxy () { 15 | JCRequester *_requester; 16 | } 17 | 18 | @end 19 | 20 | @implementation JCRequestProxy 21 | 22 | + (instancetype)sharedInstance { 23 | static dispatch_once_t pred; 24 | static JCRequestProxy *sharedInstance = nil; 25 | dispatch_once(&pred, ^{ 26 | sharedInstance = [[JCRequestProxy alloc] init]; 27 | }); 28 | return sharedInstance; 29 | } 30 | 31 | - (instancetype)init { 32 | self = [super init]; 33 | 34 | if (self) { 35 | _requester = [JCRequester sharedInstance]; 36 | } 37 | 38 | return self; 39 | } 40 | 41 | #pragma mark request 42 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(JCNetworkResponseBlock)responedBlock { 43 | if (!requestObj || ![requestObj hostName]) { 44 | return JC_ERROR_REQUESTID; 45 | } 46 | 47 | return [_requester httpGetWithRequest:requestObj entityClass:entityName withCompleteBlock:responedBlock]; 48 | } 49 | 50 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withCompleteBlock:(JCNetworkResponseBlock)responedBlock { 51 | 52 | JCRequestID requestID = [self httpGetWithRequest:requestObj entityClass:entityName withCompleteBlock:responedBlock]; 53 | 54 | if (controlObj) { 55 | [self handleControlObj:controlObj withRequestID:requestID]; 56 | } 57 | return requestID; 58 | } 59 | 60 | - (JCRequestID)httpGetWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withSucessBlock:(void (^)(id content))sucessBlock andFailedBlock:(void (^)(NSError *error))failedBlock { 61 | 62 | JCRequestID requestID = [self httpGetWithRequest:requestObj entityClass:entityName withCompleteBlock:^(JCNetworkResponse *response) { 63 | if (response.status == JCNetworkResponseStatusSuccess) { 64 | sucessBlock(response.content); 65 | return ; 66 | } 67 | failedBlock(response.error); 68 | }]; 69 | 70 | if (controlObj) { 71 | [self handleControlObj:controlObj withRequestID:requestID]; 72 | } 73 | return requestID; 74 | } 75 | 76 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withCompleteBlock:(JCNetworkResponseBlock)responedBlock { 77 | if (!requestObj || ![requestObj hostName]) { 78 | return JC_ERROR_REQUESTID; 79 | } 80 | 81 | return [_requester httpPostWithRequest:requestObj entityClass:entityName withCompleteBlock:responedBlock]; 82 | } 83 | 84 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withCompleteBlock:(JCNetworkResponseBlock)responedBlock { 85 | 86 | JCRequestID requestID = [self httpPostWithRequest:requestObj entityClass:entityName withCompleteBlock:responedBlock]; 87 | 88 | if (controlObj) { 89 | [self handleControlObj:controlObj withRequestID:requestID]; 90 | } 91 | return requestID; 92 | } 93 | 94 | - (JCRequestID)httpPostWithRequest:(JCRequestObj *)requestObj entityClass:(NSString *)entityName withControlObj:(NSObject *)controlObj withSucessBlock:(void (^)(id content))sucessBlock andFailedBlock:(void (^)(NSError *error))failedBlock { 95 | 96 | JCRequestID requestID = [self httpPostWithRequest:requestObj entityClass:entityName withCompleteBlock:^(JCNetworkResponse *response) { 97 | if (response.status == JCNetworkResponseStatusSuccess) { 98 | sucessBlock(response.content); 99 | return ; 100 | } 101 | failedBlock(response.error); 102 | }]; 103 | 104 | if (controlObj) { 105 | [self handleControlObj:controlObj withRequestID:requestID]; 106 | } 107 | return requestID; 108 | } 109 | 110 | - (JCRequestID)upLoadFileWithRequest:(JCRequestObj *)requestObj files:(NSDictionary *)files entityClass:(NSString *)entityName withUpLoadBlock:(JCNetworkResponseBlock)upLoadBlock { 111 | if (!requestObj || ![requestObj hostName]) { 112 | return JC_ERROR_REQUESTID; 113 | } 114 | return [_requester upLoadFileWithRequest:requestObj files:files entityClass:entityName withUpLoadBlock:upLoadBlock]; 115 | } 116 | 117 | - (JCRequestID)downLoadFileFrom:(NSURL *)remoteURL toFile:(NSString*)filePath withDownLoadBlock:(JCNetworkResponseBlock)responedBlock { 118 | if (!remoteURL) { 119 | return JC_ERROR_REQUESTID; 120 | } 121 | 122 | if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { 123 | [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; 124 | } 125 | 126 | return [_requester downLoadFileFrom:remoteURL toFile:filePath withDownLoadBlock:responedBlock]; 127 | } 128 | 129 | #pragma mark CacheResponed 130 | 131 | - (__kindof JCResponedObj *)getCacheResponedObj:(JCRequestObj *)requestObj entityClass:(NSString *)entityName { 132 | 133 | JCRequest *request = [[JCRequest alloc] initWithRequestObj:requestObj]; 134 | JCCacheResponed *cacheResponed = [[JCCacheResponedDispatcher sharedInstance] getCacheResponedWithKey:request.cacheKey]; 135 | 136 | if (!cacheResponed) { 137 | return nil; 138 | } 139 | 140 | NSDictionary *returnValue = cacheResponed.responedDic; 141 | 142 | if (entityName) { 143 | Class cls = NSClassFromString(entityName); 144 | NSObject *responsed = [cls yy_modelWithDictionary:returnValue]; 145 | return responsed; 146 | } 147 | 148 | return cacheResponed.responedDic; 149 | } 150 | 151 | #pragma mark ImageRequest 152 | - (void)autoLoadImageWithURL:(NSURL *)imageURL placeHolderImage:(UIImage*)image toImageView:(UIImageView *)imageView { 153 | if (!imageURL) { 154 | return ; 155 | } 156 | 157 | return [_requester autoLoadImageWithURL:imageURL placeHolderImage:image toImageView:imageView]; 158 | } 159 | 160 | - (void)loadImageWithURL:(NSURL *)imageURL completionHandler:(JCNetworkImageFetch)imageFetchBlock { 161 | if (!imageURL) { 162 | return; 163 | } 164 | return [_requester loadImageWithURL:imageURL completionHandler:imageFetchBlock]; 165 | } 166 | 167 | - (UIImage *)getImageIfExisted:(NSURL *)imageURL { 168 | if (!imageURL) { 169 | return nil; 170 | } 171 | 172 | return [_requester getImageIfExisted:imageURL]; 173 | } 174 | 175 | #pragma mark cancelRequest 176 | 177 | - (void)cancelRequestID:(JCRequestID)requestID { 178 | [_requester cancelRequest:requestID]; 179 | } 180 | 181 | - (void)cancelAllRequest { 182 | [_requester cancelAllRequest]; 183 | } 184 | 185 | - (void)clearSave { 186 | [[JCCacheResponedDispatcher sharedInstance] clearn]; 187 | } 188 | 189 | #pragma mark ControlObj 190 | 191 | - (void)handleControlObj:(NSObject *)controlObj withRequestID:(JCRequestID)requestID { 192 | NSMutableArray *requstIdArrary = [self getAllRequestID:controlObj]; 193 | 194 | if (!requstIdArrary) { 195 | [self setAllRequestID:controlObj]; 196 | requstIdArrary = [self getAllRequestID:controlObj]; 197 | 198 | SEL aSelector = NSSelectorFromString(@"dealloc"); 199 | __weak typeof(self) weakSelf = self; 200 | [controlObj aspect_hookSelector:aSelector withOptions:AspectPositionBefore usingBlock:^(id aspectInfo){ 201 | NSMutableArray *requestArrary = [weakSelf getAllRequestID:aspectInfo.instance]; 202 | [requstIdArrary enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 203 | [weakSelf cancelRequestID:[obj integerValue]]; 204 | }]; 205 | } error:nil]; 206 | } 207 | 208 | [requstIdArrary addObject:[NSNumber numberWithInt:requestID]]; 209 | } 210 | 211 | - (NSMutableArray *)getAllRequestID:(NSObject *)controlObj { 212 | NSMutableArray *requstIdArrary = objc_getAssociatedObject(controlObj, 'allRequestID'); 213 | return requstIdArrary; 214 | } 215 | 216 | - (void)setAllRequestID:(NSObject *)controlObj { 217 | NSMutableArray *requestArrary = [[NSMutableArray alloc] init]; 218 | objc_setAssociatedObject(controlObj, 'allRequestID', requestArrary, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 219 | } 220 | 221 | @end 222 | -------------------------------------------------------------------------------- /JCNetwork/Classes/Handle/JCDispatcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // JCDispatcher.m 3 | // JCNetworkNew 4 | // 5 | // Created by Jam on 13-6-21. 6 | // Copyright (c) 2013年 Jam. All rights reserved. 7 | // 8 | 9 | #import "JCDispatcher.h" 10 | #import "JCCacheResponedDispatcher.h" 11 | 12 | @implementation JCDispatcher 13 | 14 | @synthesize serviceDict = _serviceDict; 15 | 16 | + (id)sharedInstance { 17 | static dispatch_once_t pred; 18 | static JCDispatcher *sharedInstance = nil; 19 | dispatch_once(&pred, ^{ 20 | sharedInstance = [[JCDispatcher alloc] init]; 21 | }); 22 | return sharedInstance; 23 | } 24 | 25 | - (id)init { 26 | self = [super init]; 27 | 28 | if (self) { 29 | _dispatchTable = [[NSMutableDictionary alloc] init]; 30 | } 31 | 32 | return self; 33 | } 34 | 35 | #pragma mark - Handle dispatch 36 | 37 | - (void)addGetDispatchItem:(DispatchElement *)item { 38 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 39 | manager.requestSerializer = [item.request requestSerializer]; 40 | manager.requestSerializer.timeoutInterval = item.request.timeoutInterval; 41 | manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 42 | 43 | [self cancelRequest:item.requestID]; 44 | 45 | if ([self haveCacheResponedWithDispatchElement:item]) { 46 | return ; 47 | } 48 | 49 | __weak typeof(self) weakSelf = self; 50 | NSURLSessionDataTask *task = [manager GET:item.request.URLString parameters:item.request.paramsDic progress:nil success:^(NSURLSessionDataTask *task, id responseObject){ 51 | [weakSelf requestFinished:responseObject withDispatchElement:item]; 52 | } failure:^(NSURLSessionDataTask *task, NSError *error) { 53 | [weakSelf requestFailed:error withDispatchElement:item]; 54 | }]; 55 | 56 | [_dispatchTable setObject:task forKey:[NSNumber numberWithInt:item.requestID]]; 57 | } 58 | 59 | - (void)addPostDispatchItem:(DispatchElement *)item { 60 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 61 | manager.requestSerializer = [item.request requestSerializer]; 62 | manager.requestSerializer.timeoutInterval = item.request.timeoutInterval; 63 | manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 64 | 65 | [self cancelRequest:item.requestID]; 66 | 67 | if ([self haveCacheResponedWithDispatchElement:item]) { 68 | return ; 69 | } 70 | __weak typeof(self) weakSelf = self; 71 | NSURLSessionDataTask *task = [manager POST:item.request.URLString parameters:item.request.paramsDic progress:nil success:^(NSURLSessionDataTask *task, id responseObject){ 72 | [weakSelf requestFinished:responseObject withDispatchElement:item]; 73 | } failure:^(NSURLSessionDataTask *task, NSError *error) { 74 | [weakSelf requestFailed:error withDispatchElement:item]; 75 | }]; 76 | 77 | [_dispatchTable setObject:task forKey:[NSNumber numberWithInt:item.requestID]]; 78 | } 79 | 80 | - (void)addDispatchUploadItem:(DispatchElement *)item withFiles:(NSDictionary *)files { 81 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 82 | manager.requestSerializer = [item.request requestSerializer]; 83 | manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 84 | 85 | [self cancelRequest:item.requestID]; 86 | 87 | __weak typeof(self) weakSelf = self; 88 | NSURLSessionDataTask *task = [manager POST:item.request.URLString parameters:item.request.paramsDic constructingBodyWithBlock:^(id _Nonnull formData) { 89 | for (NSString *key in [files allKeys]) { 90 | [formData appendPartWithFileData:[files objectForKey:key] name:key fileName:key mimeType:@"application/octet-stream"]; 91 | } 92 | } progress:^(NSProgress * _Nonnull uploadProgress) { 93 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { 94 | [weakSelf requestFinished:responseObject withDispatchElement:item]; 95 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { 96 | [weakSelf requestFailed:error withDispatchElement:item]; 97 | }]; 98 | [_dispatchTable setObject:task forKey:[NSNumber numberWithInt:item.requestID]]; 99 | } 100 | 101 | 102 | - (void)cancelRequest:(JCRequestID)requestID { 103 | NSURLSessionDataTask *task = [_dispatchTable objectForKey:[NSNumber numberWithInt:requestID]]; 104 | if (task) { 105 | // remove dispatch item from dispatch table 106 | [_dispatchTable removeObjectForKey:[NSNumber numberWithInt:requestID]]; 107 | [task cancel]; 108 | } 109 | } 110 | 111 | - (void)cancelAllRequest { 112 | for (NSNumber *requestNumber in [_dispatchTable allKeys]) { 113 | [self cancelRequest:[requestNumber intValue]]; 114 | } 115 | } 116 | 117 | #pragma mark - Handle requests 118 | 119 | - (void)dispatchResponse:(JCNetworkResponse *)response forElement:(DispatchElement *)element { 120 | 121 | JCRequestID requestID = [element requestID]; 122 | 123 | if (element.responseBlock) { 124 | element.responseBlock(response); 125 | } 126 | 127 | // remove dispatch item from dispatch table 128 | [_dispatchTable removeObjectForKey:[NSNumber numberWithInt:requestID]]; 129 | } 130 | 131 | #pragma mark - Handle CacheResponed 132 | 133 | //缓存是否有效 134 | - (BOOL)haveCacheResponedWithDispatchElement:(DispatchElement *)element { 135 | 136 | JCCacheResponed *cacheResponed = [[JCCacheResponedDispatcher sharedInstance] getCacheResponedWithKey:element.request.cacheKey]; 137 | 138 | if (!cacheResponed) { 139 | return NO; 140 | } 141 | 142 | if (element.request.cachePolicy == JCNetWorkReturnCacheDataElseLoad) { 143 | [self handleRequestFinished:cacheResponed.responedDic withDispatchElement:element]; 144 | return YES; 145 | } 146 | 147 | //JCNetWorkReturnCacheDataReLoad策略判断是否成功 148 | NSTimeInterval currentTimeInterval = [[NSDate date] timeIntervalSince1970]; 149 | if (currentTimeInterval - cacheResponed.timeInterval >= element.request.cacheRefreshTimeInterval) { 150 | return NO; 151 | } 152 | [self handleRequestFinished:cacheResponed.responedDic withDispatchElement:element]; 153 | return YES; 154 | } 155 | 156 | #pragma mark - Handle responses 157 | 158 | - (void)requestFinished:(id)responseObject withDispatchElement:(DispatchElement *)element { 159 | 160 | JCNetworkResponse *response = [[JCNetworkResponse alloc] init]; 161 | [response setRequestID:element.requestID]; 162 | response.progress = 1.0; 163 | 164 | NSError *error = nil; 165 | 166 | id returnValue = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error]; 167 | if(!returnValue) { 168 | [self requestFailed:error withDispatchElement:element]; 169 | return ; 170 | } 171 | 172 | if (element.request.cachePolicy == JCNetWorkReturnCacheDataElseLoad || element.request.cachePolicy == JCNetWorkReturnCacheDataReLoad ) { 173 | [[JCCacheResponedDispatcher sharedInstance] saveCacheResponed:returnValue forKey:element.request.cacheKey]; 174 | } 175 | 176 | if ([element entityClassName] != nil) { 177 | Class cls = NSClassFromString(element.entityClassName); 178 | NSObject *responsed = [cls yy_modelWithDictionary:returnValue]; 179 | [response setContent:responsed]; 180 | } else { 181 | [response setContent:returnValue]; 182 | } 183 | 184 | [response setStatus:JCNetworkResponseStatusSuccess]; 185 | [self dispatchResponse:response forElement:element]; 186 | } 187 | 188 | - (void)handleRequestFinished:(NSDictionary *)responedDic withDispatchElement:(DispatchElement *)element { 189 | 190 | JCNetworkResponse *response = [[JCNetworkResponse alloc] init]; 191 | [response setRequestID:element.requestID]; 192 | response.progress = 1.0; 193 | 194 | if ([element entityClassName] != nil) { 195 | Class cls = NSClassFromString(element.entityClassName); 196 | NSObject *responsed = [cls yy_modelWithDictionary:responedDic]; 197 | [response setContent:responsed]; 198 | } else { 199 | [response setContent:responedDic]; 200 | } 201 | 202 | [response setStatus:JCNetworkResponseStatusSuccess]; 203 | [self dispatchResponse:response forElement:element]; 204 | } 205 | 206 | 207 | 208 | - (void)requestFailed:(NSError *)error withDispatchElement:(DispatchElement *)element { 209 | 210 | JCNetworkResponse *response = [[JCNetworkResponse alloc] init]; 211 | [response setRequestID:element.requestID]; 212 | [response setError:error]; 213 | [response setContent:nil]; 214 | 215 | [response setStatus:JCNetworkResponseStatusFailed]; 216 | [self dispatchResponse:response forElement:element]; 217 | } 218 | 219 | @end 220 | -------------------------------------------------------------------------------- /Example/JCNetwork.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0D6942F11DEA648F00EE6D7C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D6942F01DEA648F00EE6D7C /* LaunchScreen.storyboard */; }; 11 | 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 12 | 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; }; 13 | 6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 14 | 6003F598195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F596195388D20070C39A /* InfoPlist.strings */; }; 15 | 6003F59A195388D20070C39A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F599195388D20070C39A /* main.m */; }; 16 | 6003F59E195388D20070C39A /* JCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F59D195388D20070C39A /* JCAppDelegate.m */; }; 17 | 6003F5A7195388D20070C39A /* JCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5A6195388D20070C39A /* JCViewController.m */; }; 18 | 6003F5A9195388D20070C39A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; }; 19 | 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; }; 20 | 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 21 | 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 22 | 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; }; 23 | 6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; }; 24 | 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; 25 | BB9C28A6905BF3765050DD34 /* Pods_JCNetwork_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A6C718B14CDBB7735BD1B6F /* Pods_JCNetwork_Example.framework */; }; 26 | BDC0632B57980DD420F6424E /* Pods_JCNetwork_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C16C2AA79CD568BAF8D568F /* Pods_JCNetwork_Tests.framework */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXContainerItemProxy section */ 30 | 6003F5B3195388D20070C39A /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = 6003F582195388D10070C39A /* Project object */; 33 | proxyType = 1; 34 | remoteGlobalIDString = 6003F589195388D20070C39A; 35 | remoteInfo = JCNetwork; 36 | }; 37 | /* End PBXContainerItemProxy section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | 0D6942F01DEA648F00EE6D7C /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 41 | 15BE0DD466018047A2D55807 /* Pods-JCNetwork_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JCNetwork_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-JCNetwork_Example/Pods-JCNetwork_Example.debug.xcconfig"; sourceTree = ""; }; 42 | 28698DEA830474A27CC3DCBA /* Pods-JCNetwork_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JCNetwork_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-JCNetwork_Example/Pods-JCNetwork_Example.release.xcconfig"; sourceTree = ""; }; 43 | 33EC47DB0F3CA1975F3FF25A /* Pods-JCNetwork_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JCNetwork_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-JCNetwork_Tests/Pods-JCNetwork_Tests.debug.xcconfig"; sourceTree = ""; }; 44 | 4357E8C31ECEC887E2B7904B /* Pods-JCNetwork_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JCNetwork_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-JCNetwork_Tests/Pods-JCNetwork_Tests.release.xcconfig"; sourceTree = ""; }; 45 | 533540C69285469BA74A077F /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 46 | 6003F58A195388D20070C39A /* JCNetwork_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JCNetwork_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 48 | 6003F58F195388D20070C39A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 49 | 6003F591195388D20070C39A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 50 | 6003F595195388D20070C39A /* JCNetwork-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JCNetwork-Info.plist"; sourceTree = ""; }; 51 | 6003F597195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 52 | 6003F599195388D20070C39A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 53 | 6003F59B195388D20070C39A /* JCNetwork-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JCNetwork-Prefix.pch"; sourceTree = ""; }; 54 | 6003F59C195388D20070C39A /* JCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JCAppDelegate.h; sourceTree = ""; }; 55 | 6003F59D195388D20070C39A /* JCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JCAppDelegate.m; sourceTree = ""; }; 56 | 6003F5A5195388D20070C39A /* JCViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JCViewController.h; sourceTree = ""; }; 57 | 6003F5A6195388D20070C39A /* JCViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JCViewController.m; sourceTree = ""; }; 58 | 6003F5A8195388D20070C39A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 59 | 6003F5AE195388D20070C39A /* JCNetwork_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JCNetwork_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 60 | 6003F5AF195388D20070C39A /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 61 | 6003F5B7195388D20070C39A /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; }; 62 | 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 63 | 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; }; 64 | 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; 65 | 6A6C718B14CDBB7735BD1B6F /* Pods_JCNetwork_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_JCNetwork_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 66 | 6C16C2AA79CD568BAF8D568F /* Pods_JCNetwork_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_JCNetwork_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 67 | 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 68 | BB0BCCB176F5F03E1E9015B7 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 69 | CEF781807D10886C7E34255B /* JCNetwork.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = JCNetwork.podspec; path = ../JCNetwork.podspec; sourceTree = ""; }; 70 | /* End PBXFileReference section */ 71 | 72 | /* Begin PBXFrameworksBuildPhase section */ 73 | 6003F587195388D20070C39A /* Frameworks */ = { 74 | isa = PBXFrameworksBuildPhase; 75 | buildActionMask = 2147483647; 76 | files = ( 77 | 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */, 78 | 6003F592195388D20070C39A /* UIKit.framework in Frameworks */, 79 | 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */, 80 | BB9C28A6905BF3765050DD34 /* Pods_JCNetwork_Example.framework in Frameworks */, 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | 6003F5AB195388D20070C39A /* Frameworks */ = { 85 | isa = PBXFrameworksBuildPhase; 86 | buildActionMask = 2147483647; 87 | files = ( 88 | 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */, 89 | 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */, 90 | 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */, 91 | BDC0632B57980DD420F6424E /* Pods_JCNetwork_Tests.framework in Frameworks */, 92 | ); 93 | runOnlyForDeploymentPostprocessing = 0; 94 | }; 95 | /* End PBXFrameworksBuildPhase section */ 96 | 97 | /* Begin PBXGroup section */ 98 | 5EA43305E102A2AA94CBE8FA /* Pods */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 15BE0DD466018047A2D55807 /* Pods-JCNetwork_Example.debug.xcconfig */, 102 | 28698DEA830474A27CC3DCBA /* Pods-JCNetwork_Example.release.xcconfig */, 103 | 33EC47DB0F3CA1975F3FF25A /* Pods-JCNetwork_Tests.debug.xcconfig */, 104 | 4357E8C31ECEC887E2B7904B /* Pods-JCNetwork_Tests.release.xcconfig */, 105 | ); 106 | name = Pods; 107 | sourceTree = ""; 108 | }; 109 | 6003F581195388D10070C39A = { 110 | isa = PBXGroup; 111 | children = ( 112 | 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */, 113 | 6003F593195388D20070C39A /* Example for JCNetwork */, 114 | 6003F5B5195388D20070C39A /* Tests */, 115 | 6003F58C195388D20070C39A /* Frameworks */, 116 | 6003F58B195388D20070C39A /* Products */, 117 | 5EA43305E102A2AA94CBE8FA /* Pods */, 118 | ); 119 | sourceTree = ""; 120 | }; 121 | 6003F58B195388D20070C39A /* Products */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 6003F58A195388D20070C39A /* JCNetwork_Example.app */, 125 | 6003F5AE195388D20070C39A /* JCNetwork_Tests.xctest */, 126 | ); 127 | name = Products; 128 | sourceTree = ""; 129 | }; 130 | 6003F58C195388D20070C39A /* Frameworks */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 6003F58D195388D20070C39A /* Foundation.framework */, 134 | 6003F58F195388D20070C39A /* CoreGraphics.framework */, 135 | 6003F591195388D20070C39A /* UIKit.framework */, 136 | 6003F5AF195388D20070C39A /* XCTest.framework */, 137 | 6A6C718B14CDBB7735BD1B6F /* Pods_JCNetwork_Example.framework */, 138 | 6C16C2AA79CD568BAF8D568F /* Pods_JCNetwork_Tests.framework */, 139 | ); 140 | name = Frameworks; 141 | sourceTree = ""; 142 | }; 143 | 6003F593195388D20070C39A /* Example for JCNetwork */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | 6003F59C195388D20070C39A /* JCAppDelegate.h */, 147 | 6003F59D195388D20070C39A /* JCAppDelegate.m */, 148 | 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */, 149 | 6003F5A5195388D20070C39A /* JCViewController.h */, 150 | 6003F5A6195388D20070C39A /* JCViewController.m */, 151 | 0D6942F01DEA648F00EE6D7C /* LaunchScreen.storyboard */, 152 | 6003F5A8195388D20070C39A /* Images.xcassets */, 153 | 6003F594195388D20070C39A /* Supporting Files */, 154 | ); 155 | name = "Example for JCNetwork"; 156 | path = JCNetwork; 157 | sourceTree = ""; 158 | }; 159 | 6003F594195388D20070C39A /* Supporting Files */ = { 160 | isa = PBXGroup; 161 | children = ( 162 | 6003F595195388D20070C39A /* JCNetwork-Info.plist */, 163 | 6003F596195388D20070C39A /* InfoPlist.strings */, 164 | 6003F599195388D20070C39A /* main.m */, 165 | 6003F59B195388D20070C39A /* JCNetwork-Prefix.pch */, 166 | ); 167 | name = "Supporting Files"; 168 | sourceTree = ""; 169 | }; 170 | 6003F5B5195388D20070C39A /* Tests */ = { 171 | isa = PBXGroup; 172 | children = ( 173 | 6003F5BB195388D20070C39A /* Tests.m */, 174 | 6003F5B6195388D20070C39A /* Supporting Files */, 175 | ); 176 | path = Tests; 177 | sourceTree = ""; 178 | }; 179 | 6003F5B6195388D20070C39A /* Supporting Files */ = { 180 | isa = PBXGroup; 181 | children = ( 182 | 6003F5B7195388D20070C39A /* Tests-Info.plist */, 183 | 6003F5B8195388D20070C39A /* InfoPlist.strings */, 184 | 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */, 185 | ); 186 | name = "Supporting Files"; 187 | sourceTree = ""; 188 | }; 189 | 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */ = { 190 | isa = PBXGroup; 191 | children = ( 192 | CEF781807D10886C7E34255B /* JCNetwork.podspec */, 193 | BB0BCCB176F5F03E1E9015B7 /* README.md */, 194 | 533540C69285469BA74A077F /* LICENSE */, 195 | ); 196 | name = "Podspec Metadata"; 197 | sourceTree = ""; 198 | }; 199 | /* End PBXGroup section */ 200 | 201 | /* Begin PBXNativeTarget section */ 202 | 6003F589195388D20070C39A /* JCNetwork_Example */ = { 203 | isa = PBXNativeTarget; 204 | buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "JCNetwork_Example" */; 205 | buildPhases = ( 206 | 5AFFE4C7A09734F0196929A3 /* [CP] Check Pods Manifest.lock */, 207 | 6003F586195388D20070C39A /* Sources */, 208 | 6003F587195388D20070C39A /* Frameworks */, 209 | 6003F588195388D20070C39A /* Resources */, 210 | 76A69828781BCB5FB618E829 /* [CP] Embed Pods Frameworks */, 211 | 748C4CF022E57DCF3F03CDA6 /* [CP] Copy Pods Resources */, 212 | ); 213 | buildRules = ( 214 | ); 215 | dependencies = ( 216 | ); 217 | name = JCNetwork_Example; 218 | productName = JCNetwork; 219 | productReference = 6003F58A195388D20070C39A /* JCNetwork_Example.app */; 220 | productType = "com.apple.product-type.application"; 221 | }; 222 | 6003F5AD195388D20070C39A /* JCNetwork_Tests */ = { 223 | isa = PBXNativeTarget; 224 | buildConfigurationList = 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "JCNetwork_Tests" */; 225 | buildPhases = ( 226 | 685B7C268F4A1A9FE3795C46 /* [CP] Check Pods Manifest.lock */, 227 | 6003F5AA195388D20070C39A /* Sources */, 228 | 6003F5AB195388D20070C39A /* Frameworks */, 229 | 6003F5AC195388D20070C39A /* Resources */, 230 | EDB4E68FC6EAC8B287A98C83 /* [CP] Embed Pods Frameworks */, 231 | AB36724F8921D02C65B22024 /* [CP] Copy Pods Resources */, 232 | ); 233 | buildRules = ( 234 | ); 235 | dependencies = ( 236 | 6003F5B4195388D20070C39A /* PBXTargetDependency */, 237 | ); 238 | name = JCNetwork_Tests; 239 | productName = JCNetworkTests; 240 | productReference = 6003F5AE195388D20070C39A /* JCNetwork_Tests.xctest */; 241 | productType = "com.apple.product-type.bundle.unit-test"; 242 | }; 243 | /* End PBXNativeTarget section */ 244 | 245 | /* Begin PBXProject section */ 246 | 6003F582195388D10070C39A /* Project object */ = { 247 | isa = PBXProject; 248 | attributes = { 249 | CLASSPREFIX = JC; 250 | LastUpgradeCheck = 0720; 251 | ORGANIZATIONNAME = "贾淼"; 252 | TargetAttributes = { 253 | 6003F589195388D20070C39A = { 254 | DevelopmentTeam = 7TVSQH639C; 255 | }; 256 | 6003F5AD195388D20070C39A = { 257 | DevelopmentTeam = 7TVSQH639C; 258 | TestTargetID = 6003F589195388D20070C39A; 259 | }; 260 | }; 261 | }; 262 | buildConfigurationList = 6003F585195388D10070C39A /* Build configuration list for PBXProject "JCNetwork" */; 263 | compatibilityVersion = "Xcode 3.2"; 264 | developmentRegion = English; 265 | hasScannedForEncodings = 0; 266 | knownRegions = ( 267 | en, 268 | Base, 269 | ); 270 | mainGroup = 6003F581195388D10070C39A; 271 | productRefGroup = 6003F58B195388D20070C39A /* Products */; 272 | projectDirPath = ""; 273 | projectRoot = ""; 274 | targets = ( 275 | 6003F589195388D20070C39A /* JCNetwork_Example */, 276 | 6003F5AD195388D20070C39A /* JCNetwork_Tests */, 277 | ); 278 | }; 279 | /* End PBXProject section */ 280 | 281 | /* Begin PBXResourcesBuildPhase section */ 282 | 6003F588195388D20070C39A /* Resources */ = { 283 | isa = PBXResourcesBuildPhase; 284 | buildActionMask = 2147483647; 285 | files = ( 286 | 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */, 287 | 0D6942F11DEA648F00EE6D7C /* LaunchScreen.storyboard in Resources */, 288 | 6003F5A9195388D20070C39A /* Images.xcassets in Resources */, 289 | 6003F598195388D20070C39A /* InfoPlist.strings in Resources */, 290 | ); 291 | runOnlyForDeploymentPostprocessing = 0; 292 | }; 293 | 6003F5AC195388D20070C39A /* Resources */ = { 294 | isa = PBXResourcesBuildPhase; 295 | buildActionMask = 2147483647; 296 | files = ( 297 | 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */, 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | /* End PBXResourcesBuildPhase section */ 302 | 303 | /* Begin PBXShellScriptBuildPhase section */ 304 | 5AFFE4C7A09734F0196929A3 /* [CP] Check Pods Manifest.lock */ = { 305 | isa = PBXShellScriptBuildPhase; 306 | buildActionMask = 2147483647; 307 | files = ( 308 | ); 309 | inputPaths = ( 310 | ); 311 | name = "[CP] Check Pods Manifest.lock"; 312 | outputPaths = ( 313 | ); 314 | runOnlyForDeploymentPostprocessing = 0; 315 | shellPath = /bin/sh; 316 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 317 | showEnvVarsInLog = 0; 318 | }; 319 | 685B7C268F4A1A9FE3795C46 /* [CP] Check Pods Manifest.lock */ = { 320 | isa = PBXShellScriptBuildPhase; 321 | buildActionMask = 2147483647; 322 | files = ( 323 | ); 324 | inputPaths = ( 325 | ); 326 | name = "[CP] Check Pods Manifest.lock"; 327 | outputPaths = ( 328 | ); 329 | runOnlyForDeploymentPostprocessing = 0; 330 | shellPath = /bin/sh; 331 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 332 | showEnvVarsInLog = 0; 333 | }; 334 | 748C4CF022E57DCF3F03CDA6 /* [CP] Copy Pods Resources */ = { 335 | isa = PBXShellScriptBuildPhase; 336 | buildActionMask = 2147483647; 337 | files = ( 338 | ); 339 | inputPaths = ( 340 | ); 341 | name = "[CP] Copy Pods Resources"; 342 | outputPaths = ( 343 | ); 344 | runOnlyForDeploymentPostprocessing = 0; 345 | shellPath = /bin/sh; 346 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-JCNetwork_Example/Pods-JCNetwork_Example-resources.sh\"\n"; 347 | showEnvVarsInLog = 0; 348 | }; 349 | 76A69828781BCB5FB618E829 /* [CP] Embed Pods Frameworks */ = { 350 | isa = PBXShellScriptBuildPhase; 351 | buildActionMask = 2147483647; 352 | files = ( 353 | ); 354 | inputPaths = ( 355 | ); 356 | name = "[CP] Embed Pods Frameworks"; 357 | outputPaths = ( 358 | ); 359 | runOnlyForDeploymentPostprocessing = 0; 360 | shellPath = /bin/sh; 361 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-JCNetwork_Example/Pods-JCNetwork_Example-frameworks.sh\"\n"; 362 | showEnvVarsInLog = 0; 363 | }; 364 | AB36724F8921D02C65B22024 /* [CP] Copy Pods Resources */ = { 365 | isa = PBXShellScriptBuildPhase; 366 | buildActionMask = 2147483647; 367 | files = ( 368 | ); 369 | inputPaths = ( 370 | ); 371 | name = "[CP] Copy Pods Resources"; 372 | outputPaths = ( 373 | ); 374 | runOnlyForDeploymentPostprocessing = 0; 375 | shellPath = /bin/sh; 376 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-JCNetwork_Tests/Pods-JCNetwork_Tests-resources.sh\"\n"; 377 | showEnvVarsInLog = 0; 378 | }; 379 | EDB4E68FC6EAC8B287A98C83 /* [CP] Embed Pods Frameworks */ = { 380 | isa = PBXShellScriptBuildPhase; 381 | buildActionMask = 2147483647; 382 | files = ( 383 | ); 384 | inputPaths = ( 385 | ); 386 | name = "[CP] Embed Pods Frameworks"; 387 | outputPaths = ( 388 | ); 389 | runOnlyForDeploymentPostprocessing = 0; 390 | shellPath = /bin/sh; 391 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-JCNetwork_Tests/Pods-JCNetwork_Tests-frameworks.sh\"\n"; 392 | showEnvVarsInLog = 0; 393 | }; 394 | /* End PBXShellScriptBuildPhase section */ 395 | 396 | /* Begin PBXSourcesBuildPhase section */ 397 | 6003F586195388D20070C39A /* Sources */ = { 398 | isa = PBXSourcesBuildPhase; 399 | buildActionMask = 2147483647; 400 | files = ( 401 | 6003F59E195388D20070C39A /* JCAppDelegate.m in Sources */, 402 | 6003F5A7195388D20070C39A /* JCViewController.m in Sources */, 403 | 6003F59A195388D20070C39A /* main.m in Sources */, 404 | ); 405 | runOnlyForDeploymentPostprocessing = 0; 406 | }; 407 | 6003F5AA195388D20070C39A /* Sources */ = { 408 | isa = PBXSourcesBuildPhase; 409 | buildActionMask = 2147483647; 410 | files = ( 411 | 6003F5BC195388D20070C39A /* Tests.m in Sources */, 412 | ); 413 | runOnlyForDeploymentPostprocessing = 0; 414 | }; 415 | /* End PBXSourcesBuildPhase section */ 416 | 417 | /* Begin PBXTargetDependency section */ 418 | 6003F5B4195388D20070C39A /* PBXTargetDependency */ = { 419 | isa = PBXTargetDependency; 420 | target = 6003F589195388D20070C39A /* JCNetwork_Example */; 421 | targetProxy = 6003F5B3195388D20070C39A /* PBXContainerItemProxy */; 422 | }; 423 | /* End PBXTargetDependency section */ 424 | 425 | /* Begin PBXVariantGroup section */ 426 | 6003F596195388D20070C39A /* InfoPlist.strings */ = { 427 | isa = PBXVariantGroup; 428 | children = ( 429 | 6003F597195388D20070C39A /* en */, 430 | ); 431 | name = InfoPlist.strings; 432 | sourceTree = ""; 433 | }; 434 | 6003F5B8195388D20070C39A /* InfoPlist.strings */ = { 435 | isa = PBXVariantGroup; 436 | children = ( 437 | 6003F5B9195388D20070C39A /* en */, 438 | ); 439 | name = InfoPlist.strings; 440 | sourceTree = ""; 441 | }; 442 | /* End PBXVariantGroup section */ 443 | 444 | /* Begin XCBuildConfiguration section */ 445 | 6003F5BD195388D20070C39A /* Debug */ = { 446 | isa = XCBuildConfiguration; 447 | buildSettings = { 448 | ALWAYS_SEARCH_USER_PATHS = NO; 449 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 450 | CLANG_CXX_LIBRARY = "libc++"; 451 | CLANG_ENABLE_MODULES = YES; 452 | CLANG_ENABLE_OBJC_ARC = YES; 453 | CLANG_WARN_BOOL_CONVERSION = YES; 454 | CLANG_WARN_CONSTANT_CONVERSION = YES; 455 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 456 | CLANG_WARN_EMPTY_BODY = YES; 457 | CLANG_WARN_ENUM_CONVERSION = YES; 458 | CLANG_WARN_INT_CONVERSION = YES; 459 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 460 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 461 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 462 | COPY_PHASE_STRIP = NO; 463 | ENABLE_TESTABILITY = YES; 464 | GCC_C_LANGUAGE_STANDARD = gnu99; 465 | GCC_DYNAMIC_NO_PIC = NO; 466 | GCC_OPTIMIZATION_LEVEL = 0; 467 | GCC_PREPROCESSOR_DEFINITIONS = ( 468 | "DEBUG=1", 469 | "$(inherited)", 470 | ); 471 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 472 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 473 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 474 | GCC_WARN_UNDECLARED_SELECTOR = YES; 475 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 476 | GCC_WARN_UNUSED_FUNCTION = YES; 477 | GCC_WARN_UNUSED_VARIABLE = YES; 478 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 479 | ONLY_ACTIVE_ARCH = YES; 480 | SDKROOT = iphoneos; 481 | TARGETED_DEVICE_FAMILY = "1,2"; 482 | }; 483 | name = Debug; 484 | }; 485 | 6003F5BE195388D20070C39A /* Release */ = { 486 | isa = XCBuildConfiguration; 487 | buildSettings = { 488 | ALWAYS_SEARCH_USER_PATHS = NO; 489 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 490 | CLANG_CXX_LIBRARY = "libc++"; 491 | CLANG_ENABLE_MODULES = YES; 492 | CLANG_ENABLE_OBJC_ARC = YES; 493 | CLANG_WARN_BOOL_CONVERSION = YES; 494 | CLANG_WARN_CONSTANT_CONVERSION = YES; 495 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 496 | CLANG_WARN_EMPTY_BODY = YES; 497 | CLANG_WARN_ENUM_CONVERSION = YES; 498 | CLANG_WARN_INT_CONVERSION = YES; 499 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 500 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 501 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 502 | COPY_PHASE_STRIP = YES; 503 | ENABLE_NS_ASSERTIONS = NO; 504 | GCC_C_LANGUAGE_STANDARD = gnu99; 505 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 506 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 507 | GCC_WARN_UNDECLARED_SELECTOR = YES; 508 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 509 | GCC_WARN_UNUSED_FUNCTION = YES; 510 | GCC_WARN_UNUSED_VARIABLE = YES; 511 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 512 | SDKROOT = iphoneos; 513 | TARGETED_DEVICE_FAMILY = "1,2"; 514 | VALIDATE_PRODUCT = YES; 515 | }; 516 | name = Release; 517 | }; 518 | 6003F5C0195388D20070C39A /* Debug */ = { 519 | isa = XCBuildConfiguration; 520 | baseConfigurationReference = 15BE0DD466018047A2D55807 /* Pods-JCNetwork_Example.debug.xcconfig */; 521 | buildSettings = { 522 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 523 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 524 | DEVELOPMENT_TEAM = 7TVSQH639C; 525 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 526 | GCC_PREFIX_HEADER = "JCNetwork/JCNetwork-Prefix.pch"; 527 | INFOPLIST_FILE = "JCNetwork/JCNetwork-Info.plist"; 528 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 529 | MODULE_NAME = ExampleApp; 530 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; 531 | PRODUCT_NAME = "$(TARGET_NAME)"; 532 | TARGETED_DEVICE_FAMILY = 1; 533 | WRAPPER_EXTENSION = app; 534 | }; 535 | name = Debug; 536 | }; 537 | 6003F5C1195388D20070C39A /* Release */ = { 538 | isa = XCBuildConfiguration; 539 | baseConfigurationReference = 28698DEA830474A27CC3DCBA /* Pods-JCNetwork_Example.release.xcconfig */; 540 | buildSettings = { 541 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 542 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 543 | DEVELOPMENT_TEAM = 7TVSQH639C; 544 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 545 | GCC_PREFIX_HEADER = "JCNetwork/JCNetwork-Prefix.pch"; 546 | INFOPLIST_FILE = "JCNetwork/JCNetwork-Info.plist"; 547 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 548 | MODULE_NAME = ExampleApp; 549 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; 550 | PRODUCT_NAME = "$(TARGET_NAME)"; 551 | TARGETED_DEVICE_FAMILY = 1; 552 | WRAPPER_EXTENSION = app; 553 | }; 554 | name = Release; 555 | }; 556 | 6003F5C3195388D20070C39A /* Debug */ = { 557 | isa = XCBuildConfiguration; 558 | baseConfigurationReference = 33EC47DB0F3CA1975F3FF25A /* Pods-JCNetwork_Tests.debug.xcconfig */; 559 | buildSettings = { 560 | BUNDLE_LOADER = "$(TEST_HOST)"; 561 | DEVELOPMENT_TEAM = 7TVSQH639C; 562 | FRAMEWORK_SEARCH_PATHS = ( 563 | "$(SDKROOT)/Developer/Library/Frameworks", 564 | "$(inherited)", 565 | "$(DEVELOPER_FRAMEWORKS_DIR)", 566 | ); 567 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 568 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; 569 | GCC_PREPROCESSOR_DEFINITIONS = ( 570 | "DEBUG=1", 571 | "$(inherited)", 572 | ); 573 | INFOPLIST_FILE = "Tests/Tests-Info.plist"; 574 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; 575 | PRODUCT_NAME = "$(TARGET_NAME)"; 576 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JCNetwork_Example.app/JCNetwork_Example"; 577 | WRAPPER_EXTENSION = xctest; 578 | }; 579 | name = Debug; 580 | }; 581 | 6003F5C4195388D20070C39A /* Release */ = { 582 | isa = XCBuildConfiguration; 583 | baseConfigurationReference = 4357E8C31ECEC887E2B7904B /* Pods-JCNetwork_Tests.release.xcconfig */; 584 | buildSettings = { 585 | BUNDLE_LOADER = "$(TEST_HOST)"; 586 | DEVELOPMENT_TEAM = 7TVSQH639C; 587 | FRAMEWORK_SEARCH_PATHS = ( 588 | "$(SDKROOT)/Developer/Library/Frameworks", 589 | "$(inherited)", 590 | "$(DEVELOPER_FRAMEWORKS_DIR)", 591 | ); 592 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 593 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; 594 | INFOPLIST_FILE = "Tests/Tests-Info.plist"; 595 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; 596 | PRODUCT_NAME = "$(TARGET_NAME)"; 597 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JCNetwork_Example.app/JCNetwork_Example"; 598 | WRAPPER_EXTENSION = xctest; 599 | }; 600 | name = Release; 601 | }; 602 | /* End XCBuildConfiguration section */ 603 | 604 | /* Begin XCConfigurationList section */ 605 | 6003F585195388D10070C39A /* Build configuration list for PBXProject "JCNetwork" */ = { 606 | isa = XCConfigurationList; 607 | buildConfigurations = ( 608 | 6003F5BD195388D20070C39A /* Debug */, 609 | 6003F5BE195388D20070C39A /* Release */, 610 | ); 611 | defaultConfigurationIsVisible = 0; 612 | defaultConfigurationName = Release; 613 | }; 614 | 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "JCNetwork_Example" */ = { 615 | isa = XCConfigurationList; 616 | buildConfigurations = ( 617 | 6003F5C0195388D20070C39A /* Debug */, 618 | 6003F5C1195388D20070C39A /* Release */, 619 | ); 620 | defaultConfigurationIsVisible = 0; 621 | defaultConfigurationName = Release; 622 | }; 623 | 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "JCNetwork_Tests" */ = { 624 | isa = XCConfigurationList; 625 | buildConfigurations = ( 626 | 6003F5C3195388D20070C39A /* Debug */, 627 | 6003F5C4195388D20070C39A /* Release */, 628 | ); 629 | defaultConfigurationIsVisible = 0; 630 | defaultConfigurationName = Release; 631 | }; 632 | /* End XCConfigurationList section */ 633 | }; 634 | rootObject = 6003F582195388D10070C39A /* Project object */; 635 | } 636 | --------------------------------------------------------------------------------