├── CPNetwoking
├── Assets
│ └── .gitkeep
└── Classes
│ ├── .gitkeep
│ ├── NSString+CFXValidateUrl.h
│ ├── UIViewController+CFXExtension.h
│ ├── CFXNetworkingManager.h
│ ├── NSString+CFXValidateUrl.m
│ ├── CFXNetworkingManager.m
│ ├── UIViewController+CFXExtension.m
│ ├── CFXNetworking.h
│ └── CFXNetworking.m
├── _Pods.xcodeproj
├── Example
├── Tests
│ ├── en.lproj
│ │ └── InfoPlist.strings
│ ├── Tests-Prefix.pch
│ ├── Tests-Info.plist
│ └── Tests.m
├── CPNetwoking
│ ├── en.lproj
│ │ └── InfoPlist.strings
│ ├── CFXViewController.h
│ ├── CFXAppDelegate.h
│ ├── CPNetwoking-Prefix.pch
│ ├── main.m
│ ├── Images.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ └── LaunchImage.launchimage
│ │ │ └── Contents.json
│ ├── CFXViewController.m
│ ├── Main.storyboard
│ ├── CPNetwoking-Info.plist
│ └── CFXAppDelegate.m
├── CPNetwoking.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── xcschemes
│ │ │ └── CPNetwoking-Example.xcscheme
│ └── project.pbxproj
├── CPNetwoking.xcworkspace
│ └── contents.xcworkspacedata
└── Podfile
├── .travis.yml
├── .gitignore
├── LICENSE
├── CPNetwoking.podspec
└── README.md
/CPNetwoking/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/_Pods.xcodeproj:
--------------------------------------------------------------------------------
1 | Example/Pods/Pods.xcodeproj
--------------------------------------------------------------------------------
/Example/Tests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/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 FBSnapshotTestCase;
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/Example/CPNetwoking.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/NSString+CFXValidateUrl.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+CFXValidateUrl.h
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import
10 |
11 | @interface NSString (CFXValidateUrl)
12 |
13 | - (BOOL)cfx_validateUrl;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/CFXViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // CFXViewController.h
3 | // CPNetwoking
4 | //
5 | // Created by xiaochengfei on 10/18/2016.
6 | // Copyright (c) 2016 xiaochengfei. All rights reserved.
7 | //
8 |
9 | @import UIKit;
10 |
11 | @interface CFXViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Example/CPNetwoking.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Example/Podfile:
--------------------------------------------------------------------------------
1 | #use_frameworks!
2 |
3 |
4 | pod 'ReactiveCocoa', '~> 2.5'
5 | pod 'AFNetworking', '~> 3.1.0'
6 | pod 'JSONModel', '~> 1.7.0'
7 |
8 | target 'CPNetwoking_Example' do
9 | pod 'CPNetwoking', :path => '../'
10 | target 'CPNetwoking_Tests' do
11 | inherit! :search_paths
12 |
13 | #pod 'FBSnapshotTestCase'
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/UIViewController+CFXExtension.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+CFXExtension.h
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface UIViewController (CFXExtension)
13 |
14 | - (RACSignal *)cfx_httpTakeUntilSignal;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/CFXAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // CFXAppDelegate.h
3 | // CPNetwoking
4 | //
5 | // Created by xiaochengfei on 10/18/2016.
6 | // Copyright (c) 2016 xiaochengfei. All rights reserved.
7 | //
8 |
9 | @import UIKit;
10 |
11 | @interface CFXAppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/CPNetwoking-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 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // CPNetwoking
4 | //
5 | // Created by xiaochengfei on 10/18/2016.
6 | // Copyright (c) 2016 xiaochengfei. All rights reserved.
7 | //
8 |
9 | @import UIKit;
10 | #import "CFXAppDelegate.h"
11 |
12 | int main(int argc, char * argv[])
13 | {
14 | @autoreleasepool {
15 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([CFXAppDelegate class]));
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/CFXNetworkingManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // CFXNetworkingManager.h
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import
10 |
11 | @interface CFXNetworkingManager : NSObject
12 |
13 | @property (nonatomic, strong) NSOperationQueue *cfxMainQueue;
14 | @property (nonatomic, assign) NSInteger maxOperationCount;
15 |
16 | + (CFXNetworkingManager*)sharedInstance;
17 |
18 | - (void)addOperation:(NSOperation*)operation;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # references:
2 | # * http://www.objc.io/issue-6/travis-ci.html
3 | # * https://github.com/supermarin/xcpretty#usage
4 |
5 | osx_image: xcode7.3
6 | language: objective-c
7 | # cache: cocoapods
8 | # podfile: Example/Podfile
9 | # before_install:
10 | # - gem install cocoapods # Since Travis is not always on latest version
11 | # - pod install --project-directory=Example
12 | script:
13 | - set -o pipefail && xcodebuild test -workspace Example/CPNetwoking.xcworkspace -scheme CPNetwoking-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
14 | - pod lib lint
15 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/Example/Tests/Tests.m:
--------------------------------------------------------------------------------
1 | //
2 | // CPNetwokingTests.m
3 | // CPNetwokingTests
4 | //
5 | // Created by xiaochengfei on 10/18/2016.
6 | // Copyright (c) 2016 xiaochengfei. All rights reserved.
7 | //
8 |
9 | @import XCTest;
10 |
11 | @interface Tests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation Tests
16 |
17 | - (void)setUp
18 | {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown
24 | {
25 | // Put teardown code here. This method is called after the invocation of each test method in the class.
26 | [super tearDown];
27 | }
28 |
29 | - (void)testExample
30 | {
31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
32 | }
33 |
34 | @end
35 |
36 |
--------------------------------------------------------------------------------
/.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 | *.moved-aside
17 | DerivedData
18 | *.hmap
19 | *.ipa
20 | *.xcodeproj/xcuserdata/*
21 | .idea/
22 |
23 | # Bundler
24 | .bundle
25 |
26 | Carthage
27 | # We recommend against adding the Pods directory to your .gitignore. However
28 | # you should judge for yourself, the pros and cons are mentioned at:
29 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
30 | #
31 | # Note: if you ignore the Pods directory, make sure to uncomment
32 | # `pod install` in .travis.yml
33 | #
34 | Pods/
35 | Podfile.lock
36 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/NSString+CFXValidateUrl.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+CFXValidateUrl.m
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import "NSString+CFXValidateUrl.h"
10 |
11 | @implementation NSString (CFXValidateUrl)
12 |
13 | - (BOOL)cfx_validateUrl {
14 | NSUInteger length = [self length];
15 | if (length) {
16 | NSError *error = nil;
17 | NSDataDetector *dataDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
18 | if (dataDetector && !error) {
19 | NSRange range = NSMakeRange(0, length);
20 | NSRange notFoundRange = (NSRange){NSNotFound, 0};
21 | NSRange linkRange = [dataDetector rangeOfFirstMatchInString:self options:0 range:range];
22 | if (!NSEqualRanges(notFoundRange, linkRange) && NSEqualRanges(range, linkRange)) {
23 | return YES;
24 | }
25 | }
26 | }
27 | return NO;
28 | }
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/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 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 |
3 | Copyright (c) 2016 Chengfei Xiao
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 |
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 |
25 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/CFXNetworkingManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // CFXNetworkingManager.m
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import "CFXNetworkingManager.h"
10 |
11 | @implementation CFXNetworkingManager
12 |
13 | static CFXNetworkingManager *SINGLETON = nil;
14 |
15 | #pragma mark - Public Method
16 |
17 | + (id)sharedInstance {
18 | static dispatch_once_t onceToken;
19 | dispatch_once(&onceToken, ^{
20 | SINGLETON = [[CFXNetworkingManager alloc] init];
21 | });
22 | return SINGLETON;
23 | }
24 |
25 | - (id) init {
26 | self = [super init];
27 | if (self) {
28 | self.maxOperationCount = 4;
29 | }
30 | return self;
31 | }
32 |
33 | - (NSOperationQueue *)cfxMainQueue {
34 | if (!_cfxMainQueue) {
35 | _cfxMainQueue = [[NSOperationQueue alloc] init];
36 | _cfxMainQueue.name = @"CFXRequest.mainQueue";
37 | [_cfxMainQueue setMaxConcurrentOperationCount:self.maxOperationCount];
38 | }
39 | return _cfxMainQueue;
40 | }
41 |
42 | - (void)addOperation:(NSOperation*)operation {
43 | if (!operation) {
44 | return;
45 | }
46 | [self.cfxMainQueue addOperation:operation];
47 | }
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/UIViewController+CFXExtension.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+CFXExtension.m
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import "UIViewController+CFXExtension.h"
10 |
11 | @implementation UIViewController (CFXExtension)
12 |
13 | - (RACSignal *)cfx_httpTakeUntilSignal {
14 |
15 | @weakify(self);
16 | return [RACSignal createSignal:^RACDisposable *(id subscriber) {
17 | @strongify(self);
18 | RACDisposable *viewWillDisappearSignal = [[self rac_signalForSelector:@selector(viewWillDisappear:)]subscribeNext:^(id x) {
19 | [subscriber sendNext:@0];
20 | }];
21 | RACDisposable *viewWillAppearSignal = [[self rac_signalForSelector:@selector(viewWillAppear:)]subscribeNext:^(id x) {
22 | [subscriber sendNext:@1];
23 | }];
24 | [self.rac_deallocDisposable addDisposable:[RACDisposable disposableWithBlock:^{
25 | [subscriber sendCompleted];
26 | }]];
27 | return [RACDisposable disposableWithBlock:^{
28 | [viewWillDisappearSignal dispose];
29 | [viewWillAppearSignal dispose];
30 | }];
31 | }];
32 | }
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/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 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/CFXViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // CFXViewController.m
3 | // CPNetwoking
4 | //
5 | // Created by xiaochengfei on 10/18/2016.
6 | // Copyright (c) 2016 xiaochengfei. All rights reserved.
7 | //
8 |
9 | #import "CFXViewController.h"
10 | #import
11 | #import
12 |
13 | @interface CFXViewController ()
14 |
15 | @end
16 |
17 | @implementation CFXViewController
18 |
19 | - (void)viewDidLoad
20 | {
21 | [super viewDidLoad];
22 | // Do any additional setup after loading the view, typically from a nib.
23 |
24 | [CFXNetworking requestWithDomain:@"https://itunes.apple.com/"
25 | APIName:@"lookup"
26 | type:CFXGetRequestType
27 | params:^(CFXAPIParams *params) {
28 | [params addParamValue:@(507704613) forKey:@"id"];
29 | }
30 | modelClass:nil
31 | success:^(id model, NSDictionary *dic) {
32 | NSLog(@"model: %@ ,dic: %@",model,dic);
33 | }failed:^(NSError *err) {
34 | NSLog(@"%@",err);
35 | }takeUntil:[self cfx_httpTakeUntilSignal]];
36 | }
37 |
38 | - (void)didReceiveMemoryWarning
39 | {
40 | [super didReceiveMemoryWarning];
41 | // Dispose of any resources that can be recreated.
42 | }
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/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 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/CPNetwoking-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 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 | NSAppTransportSecurity
47 |
48 | NSAllowsArbitraryLoads
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/CPNetwoking.podspec:
--------------------------------------------------------------------------------
1 | #
2 | # Be sure to run `pod lib lint CPNetwoking.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 = 'CPNetwoking'
11 | s.version = '0.1.1'
12 | s.summary = 'CPNetworking is a HTTP component which encapsulate AFNetworking.'
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 | TODO: Add long description of the pod here.
22 | DESC
23 |
24 | s.homepage = 'https://github.com/crespoxiao/CPNetworking'
25 | # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
26 | s.license = { :type => 'MIT', :file => 'LICENSE' }
27 | s.author = { 'xiaochengfei' => '40176452@qq.com' }
28 | s.source = { :git => 'https://github.com/crespoxiao/CPNetworking.git', :tag => s.version.to_s }
29 | # s.social_media_url = 'https://twitter.com/'
30 |
31 | s.ios.deployment_target = '8.0'
32 |
33 | s.source_files = 'CPNetwoking/Classes/**/*'
34 |
35 | # s.resource_bundles = {
36 | # 'CPNetwoking' => ['CPNetwoking/Assets/*.png']
37 | # }
38 |
39 | # s.public_header_files = 'Pod/Classes/**/*.h'
40 | s.frameworks = 'UIKit', 'Foundation'
41 | s.dependency 'AFNetworking', '~> 3.1.0'
42 | s.dependency 'ReactiveCocoa', '~> 2.5'
43 | s.dependency 'JSONModel', '~> 1.7.0'
44 |
45 | end
46 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/CFXNetworking.h:
--------------------------------------------------------------------------------
1 | //
2 | // CFXNetworking.h
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 |
13 | @class CFXAPIParams;
14 |
15 | typedef void(^CFXSetParamsBlock)(CFXAPIParams *params);
16 | typedef void(^CFXSuccessBlock)(id model, NSDictionary *dic);
17 | typedef void(^CFXFailedBlock)(NSError *err);
18 |
19 | typedef NS_ENUM(NSUInteger, CFXRequestType) {
20 | CFXGetRequestType,
21 | CFXPostRequestType
22 | };
23 |
24 |
25 | @interface CFXNetworking : NSOperation
26 |
27 | /**
28 | *
29 | * @param domain set domain
30 | * @param api set api name
31 | * @param type get/post
32 | * @param paramsBlock set params
33 | * @param jsonModelClass if nil, the obj model in succBlock is nil
34 | * @param succBlock request succeed with result
35 | * @param failBlock request failed
36 | * @param signal when the signal sendNext with @0, succBlock/failBlock would not run
37 | */
38 | + (CFXNetworking *)requestWithDomain:(NSString *)domain
39 | APIName:(NSString *)api
40 | type:(CFXRequestType)type
41 | params:(CFXSetParamsBlock)paramsBlock
42 | modelClass:(Class)jsonModelClass
43 | success:(CFXSuccessBlock)succBlock
44 | failed:(CFXFailedBlock)failBlock
45 | takeUntil:(RACSignal *)signal;
46 |
47 | - (void)cancel;
48 |
49 | @end
50 |
51 |
52 |
53 | @interface CFXAPIParams : NSObject
54 |
55 | @property (nonatomic, assign ) NSInteger timeOutInterval;
56 | @property (nonatomic, assign ) NSInteger retryCount;
57 | @property (nonatomic, assign ) NSInteger retryInterval;
58 | @property (nonatomic, assign ) BOOL isSerialRequest;
59 |
60 | - (void)addParamValue:(id)value forKey:(id)key;
61 | - (void)addParamsDic:(NSDictionary*)dic;
62 | - (void)setParamsDic:(NSDictionary*)dic;
63 |
64 | @end
65 |
66 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CPNetwoking
2 |
3 | [](https://travis-ci.org/xiaochengfei/CPNetwoking)
4 | [](http://cocoapods.org/pods/CPNetwoking)
5 | [](http://cocoapods.org/pods/CPNetwoking)
6 | [](http://cocoapods.org/pods/CPNetwoking)
7 |
8 | ## Example
9 |
10 | To run the example project, clone the repo, and run `pod install` from the Example directory first.
11 |
12 | ## Requirements
13 | iOS8+
14 |
15 | ## Installation
16 |
17 | CPNetwoking is available through [CocoaPods](http://cocoapods.org). To install
18 | it, simply add the following line to your Podfile:
19 |
20 | ```ruby
21 | pod "CPNetwoking"
22 | ```
23 |
24 | ## Guide
25 |
26 | [CFXNetworking requestWithDomain:@"https://itunes.apple.com/"
27 | APIName:@"lookup"
28 | type:CFXGetRequestType
29 | params:^(CFXAPIParams *params) {
30 | [params addParamValue:@(507704613) forKey:@"id"];
31 | }
32 | modelClass:nil
33 | success:^(id model, NSDictionary *dic) {
34 | NSLog(@"model: %@ ,dic: %@",model,dic);
35 | }failed:^(NSError *err) {
36 | NSLog(@"%@",err);
37 | }takeUntil:[self cfx_httpTakeUntilSignal]];
38 |
39 |
40 | check the dependency info below. if the version is defferent in the Podfile of your project, just clone this repo and add floder CPNetwoking to you project.
41 |
42 | s.dependency 'AFNetworking', '~> 3.1.0'
43 | s.dependency 'ReactiveCocoa', '~> 2.5'
44 | s.dependency 'JSONModel', '~> 1.7.0'
45 |
46 | ## Author
47 |
48 | CrespoXiao
49 |
50 | ## License
51 |
52 | CPNetwoking is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
53 |
--------------------------------------------------------------------------------
/Example/CPNetwoking/CFXAppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // CFXAppDelegate.m
3 | // CPNetwoking
4 | //
5 | // Created by xiaochengfei on 10/18/2016.
6 | // Copyright (c) 2016 xiaochengfei. All rights reserved.
7 | //
8 |
9 | #import "CFXAppDelegate.h"
10 |
11 | @implementation CFXAppDelegate
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 |
--------------------------------------------------------------------------------
/Example/CPNetwoking.xcodeproj/xcshareddata/xcschemes/CPNetwoking-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 |
--------------------------------------------------------------------------------
/CPNetwoking/Classes/CFXNetworking.m:
--------------------------------------------------------------------------------
1 | //
2 | // CFXNetworking.m
3 | // Pods
4 | //
5 | // Created by xiaochengfei on 16/10/18.
6 | //
7 | //
8 |
9 | #import "CFXNetworking.h"
10 | #import "CFXNetworkingManager.h"
11 | #import "NSString+CFXValidateUrl.h"
12 | #import
13 | #import
14 |
15 |
16 | #define CFXSafeBlockRun(block, ...) block ? block(__VA_ARGS__) : nil
17 |
18 | #ifdef DEBUG
19 | # define CFXLog(fmt, ...) NSLog((@"[CFXNetworking][%s][Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
20 | #else
21 | # define CFXLog(...)
22 | #endif
23 |
24 |
25 |
26 | @interface CFXAPIParams ()
27 |
28 | @property (nonatomic, strong) NSString *domain;
29 | @property (nonatomic, strong) NSString *api_name;
30 | @property (nonatomic, strong) NSMutableDictionary *params;
31 |
32 | @end
33 |
34 |
35 | @implementation CFXAPIParams
36 |
37 | - (instancetype)init {
38 | self = [super init];
39 | if (self) {
40 | self.params = [NSMutableDictionary dictionary];
41 | }
42 | return self;
43 | }
44 |
45 | - (void)addParamValue:(id)value forKey:(id)key {
46 | [self.params setValue:value forKey:key];
47 | }
48 |
49 | - (void)addParamsDic:(NSDictionary*)dic {
50 | [self.params addEntriesFromDictionary:dic];
51 | }
52 |
53 | - (void)setParamsDic:(NSDictionary *)dic {
54 | [self.params setDictionary:dic];
55 | }
56 |
57 | @end
58 |
59 |
60 |
61 |
62 | typedef void(^CFXSuccessRequestAPIBlock)(NSDictionary *respDic);
63 | typedef void(^CFXFailedRequestAPIBlock)(NSError *err);
64 | typedef NSInteger (^CFXRetryDelayCalcBlock)(NSInteger, NSInteger, NSInteger);
65 |
66 | static inline BOOL CFXNetworking_isKindOfClass(Class parent, Class child) {
67 | for (Class cls = child; cls; cls = class_getSuperclass(cls)) {
68 | if (cls == parent) {
69 | return YES;
70 | }
71 | }
72 | return NO;
73 | }
74 |
75 | @interface CFXNetworking ()
76 |
77 | @property (nonatomic, strong) CFXAPIParams *apiParams;
78 | @property (nonatomic, assign) CFXRequestType requestType;
79 | @property (nonatomic, strong) NSString *modelClassString;
80 | @property (nonatomic, assign) BOOL isCallBackEnabled;
81 | @property (nonatomic, copy ) CFXSuccessBlock succBlock;
82 | @property (nonatomic, copy ) CFXFailedBlock failBlock;
83 | //for retry
84 | @property (nonatomic, strong) NSDictionary *tasksDict;
85 | @property (nonatomic, copy ) CFXRetryDelayCalcBlock retryDelayCalcBlock;
86 |
87 | @end
88 |
89 |
90 | @implementation CFXNetworking
91 |
92 | + (CFXNetworking *)requestWithDomain:(NSString *)domain
93 | APIName:(NSString *)api
94 | type:(CFXRequestType)type
95 | params:(CFXSetParamsBlock)paramsBlock
96 | modelClass:(Class)jsonModelClass
97 | success:(CFXSuccessBlock)succBlock
98 | failed:(CFXFailedBlock)failBlock
99 | takeUntil:(RACSignal *)signal {
100 |
101 | CFXNetworking *requestAPI = [[CFXNetworking alloc] init];
102 |
103 | CFXAPIParams *tmpParams = [[CFXAPIParams alloc] init];
104 | tmpParams.domain = domain;
105 | tmpParams.api_name = api;
106 | CFXSafeBlockRun(paramsBlock, tmpParams);
107 | if (!tmpParams.timeOutInterval) {
108 | tmpParams.timeOutInterval = 10;
109 | }
110 | requestAPI.apiParams = tmpParams;
111 | requestAPI.requestType = type;
112 | requestAPI.succBlock = succBlock;
113 | requestAPI.failBlock = failBlock;
114 | if (jsonModelClass) {
115 | requestAPI.modelClassString = NSStringFromClass(jsonModelClass);
116 | }
117 | if (signal) {
118 | [[signal takeUntil:[requestAPI rac_willDeallocSignal]] subscribeNext:^(id x) {
119 | if (x && [x isKindOfClass:[NSNumber class]]) {
120 | requestAPI.isCallBackEnabled = [x integerValue];
121 | }
122 | }];
123 | }
124 | if (requestAPI.apiParams.isSerialRequest) {
125 | for (CFXNetworking * op in [CFXNetworkingManager sharedInstance].cfxMainQueue.operations) {
126 | if (!op.isFinished && !op.isCancelled && [requestAPI.apiParams.api_name isEqualToString:op.apiParams.api_name]) {
127 | [requestAPI failedForException];
128 | return requestAPI;
129 | }
130 | }
131 | }
132 | [requestAPI startRequest];
133 | return requestAPI;
134 | }
135 |
136 | #pragma mark - life cycle
137 |
138 | - (instancetype)init{
139 | self = [super init];
140 | if (self) {
141 | self.isCallBackEnabled = YES;
142 | }
143 | return self;
144 | }
145 |
146 | - (void)main {
147 | @autoreleasepool {
148 | if(self.isCancelled){
149 | return;
150 | }
151 |
152 | [self requestWithAutoRetry:self.apiParams.retryCount
153 | retryInterval:self.apiParams.retryInterval
154 | timeOut:self.apiParams.timeOutInterval];
155 | }
156 | }
157 |
158 | - (void)startRequest {
159 | @weakify(self);
160 | [[CFXNetworkingManager sharedInstance]addOperation:(NSOperation*)self_weak_];
161 | }
162 |
163 | - (void)cancel {
164 | [super cancel];
165 | }
166 |
167 | #pragma mark - getter
168 |
169 | - (NSDictionary *)tasksDict {
170 | if (!_tasksDict) {
171 | _tasksDict = [NSDictionary dictionary];
172 | }
173 | return _tasksDict;
174 | }
175 |
176 | - (CFXRetryDelayCalcBlock)retryDelayCalcBlock {
177 | if (!_retryDelayCalcBlock) {
178 | _retryDelayCalcBlock = ^NSInteger(NSInteger totalRetries, NSInteger currentRetry, NSInteger delayInSecondsSpecified) {
179 | return delayInSecondsSpecified;
180 | };
181 | }
182 | return _retryDelayCalcBlock;
183 | }
184 |
185 | #pragma mark - retry
186 |
187 | - (NSURLSessionDataTask *)requestUrlWithAutoRetry:(NSInteger)retriesRemaining
188 | retryInterval:(NSInteger)intervalInSeconds
189 | originalRequestCreator:(NSURLSessionDataTask *(^)
190 | (void (^)(NSURLSessionDataTask *requestTask, NSError *requestError)))taskCreator
191 | originalFailure:(void(^)(NSURLSessionDataTask *failTask, NSError *failError))failure {
192 | id taskcreatorCopy = [taskCreator copy];
193 | void(^retryBlock)(NSURLSessionDataTask *, NSError *) = ^(NSURLSessionDataTask *task, NSError *error) {
194 | NSMutableDictionary *retryOperationDict = self.tasksDict[[NSString stringWithFormat:@"task_address_%lu",(unsigned long)[task hash]]];
195 | NSInteger originalRetryCount = [retryOperationDict[@"originalRetryCount"] integerValue];
196 | NSInteger retriesRemainingCount = [retryOperationDict[@"retriesRemainingCount"] integerValue];
197 | if (retriesRemainingCount > 0) {
198 | CFXLog(@"AutoRetry: Request failed: %@, retry %ld out of %ld begining...",
199 | error.localizedDescription, (long)(originalRetryCount - retriesRemainingCount + 1), (long)originalRetryCount);
200 | void (^addRetryOperation)() = ^{
201 | [self requestUrlWithAutoRetry:retriesRemaining - 1
202 | retryInterval:intervalInSeconds
203 | originalRequestCreator:taskCreator
204 | originalFailure:failure];
205 | };
206 | CFXRetryDelayCalcBlock delayCalc = self.retryDelayCalcBlock;
207 | NSInteger intervalToWait = delayCalc(originalRetryCount, retriesRemainingCount, intervalInSeconds);
208 | if (intervalToWait > 0) {
209 | CFXLog(@"AutoRetry: Delaying retry for %ld seconds...", (long)intervalToWait);
210 | dispatch_time_t delay = dispatch_time(0, (int64_t)(intervalToWait * NSEC_PER_SEC));
211 | dispatch_after(delay, dispatch_get_main_queue(), ^(void){
212 | addRetryOperation();
213 | });
214 | } else {
215 | addRetryOperation();
216 | }
217 | } else {
218 | CFXLog(@"AutoRetry: Request failed %ld times: %@", (long)originalRetryCount, error.localizedDescription);
219 | failure(task, error);
220 | CFXLog(@"AutoRetry: done.");
221 | }
222 | };
223 |
224 | NSURLSessionDataTask *task = taskCreator(retryBlock);
225 | NSMutableDictionary *taskDict = self.tasksDict[taskcreatorCopy];
226 | if (!taskDict) {
227 | taskDict = [NSMutableDictionary dictionary];
228 | taskDict[@"originalRetryCount"] = @(retriesRemaining);
229 | }
230 | taskDict[@"retriesRemainingCount"] = @(retriesRemaining);
231 | NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithDictionary:self.tasksDict];
232 | newDict[[NSString stringWithFormat:@"task_address_%p",task]] = taskDict;
233 | self.tasksDict = newDict;
234 | return task;
235 | }
236 |
237 | #pragma mark - Reuqest method
238 |
239 | - (void)failedForException {
240 | if (self.isCallBackEnabled) {
241 | NSError *error = [self checkErrorWithResDic:nil];//server 4xx/5xx
242 | if (error) {
243 | CFXSafeBlockRun(self.failBlock,error);
244 | }
245 | }
246 | }
247 |
248 | - (NSURLSessionDataTask *)requestWithAutoRetry:(NSInteger)retryCount
249 | retryInterval:(NSInteger)interval
250 | timeOut:(NSUInteger)timeOut {
251 | if (!self.apiParams.domain || ![self.apiParams.domain length]) {
252 | [self failedForException];
253 | return nil;
254 | }
255 | if (!self.apiParams.api_name || ![self.apiParams.api_name length]) {
256 | [self failedForException];
257 | return nil;
258 | }
259 | NSString *apiPath = [self.apiParams.domain stringByAppendingString:self.apiParams.api_name];
260 | if (![apiPath cfx_validateUrl]) {
261 | [self failedForException];
262 | return nil;
263 | }
264 |
265 | return [self requestWithAPIPath:apiPath type:self.requestType params:self.apiParams.params success:^(NSDictionary *respDic) {
266 | NSError *error = [self checkErrorWithResDic:respDic];
267 | if (error) {
268 | if (self.isCallBackEnabled) {
269 | CFXSafeBlockRun(self.failBlock,error);
270 | }
271 | } else {
272 | id model;
273 | BOOL isSuccessCallBack = NO;
274 | if (self.modelClassString) {
275 | Class jsonModelClass = NSClassFromString(self.modelClassString);
276 | model = [[jsonModelClass alloc]init];
277 | if ([model isKindOfClass:[JSONModel class]]) {
278 | if (respDic && [respDic isKindOfClass:[NSDictionary class]]) {
279 | model = [self transferResDataToModel:respDic];
280 | if (model) {
281 | isSuccessCallBack = YES;
282 | }
283 | }
284 | }
285 | } else if (respDic && [respDic isKindOfClass:[NSDictionary class]]) {
286 | isSuccessCallBack = YES;
287 | }
288 | if (self.isCallBackEnabled) {
289 | if (isSuccessCallBack) {
290 | CFXSafeBlockRun(self.succBlock,model,respDic);
291 | } else {
292 | [self failedForException];
293 | }
294 | }
295 | }
296 | } failed:^(NSError *err) {
297 | if (self.isCallBackEnabled) {
298 | CFXSafeBlockRun(self.failBlock,err);
299 | }
300 | } autoRetry:retryCount retryInterval:interval timeOut:timeOut];
301 | }
302 |
303 | #pragma mark - private methods
304 |
305 | - (NSURLSessionDataTask *)requestWithAPIPath:(NSString *)apiPath
306 | type:(CFXRequestType)type
307 | params:(NSDictionary *)paramsDic
308 | success:(CFXSuccessRequestAPIBlock)succ
309 | failed:(CFXFailedRequestAPIBlock)fail
310 | autoRetry:(NSUInteger)retryCount
311 | retryInterval:(NSUInteger)interval
312 | timeOut:(NSUInteger)timeOut {
313 |
314 |
315 | // upload if contains files
316 | if (type == CFXPostRequestType) {
317 | NSInteger uploadFiles = 0;
318 | for (NSString *key in [paramsDic allKeys]){
319 | id value = paramsDic[key];
320 | if ([value isKindOfClass:[NSData class]]){
321 | uploadFiles += 1;
322 | }
323 | }
324 | if (uploadFiles) {
325 | //post multipart/form-data
326 | return [self uploadMultiPartFileWithAPIPath:apiPath params:paramsDic success:^(NSDictionary *respDic) {
327 | CFXSafeBlockRun(succ,respDic);
328 | } failed:^(NSError *err) {
329 | CFXSafeBlockRun(fail,err);
330 | } autoRetry:retryCount retryInterval:interval timeOut:timeOut];
331 | }
332 | }
333 |
334 | // normal http request
335 | AFHTTPSessionManager *httpClient = [AFHTTPSessionManager manager];
336 | if (timeOut > 2 && timeOut < 30) {
337 | httpClient.requestSerializer.timeoutInterval = timeOut;
338 | } else {
339 | httpClient.requestSerializer.timeoutInterval = 30.0f;
340 | }
341 | if (type == CFXPostRequestType) {
342 | return [self requestUrlWithAutoRetry:retryCount retryInterval:interval originalRequestCreator:^NSURLSessionDataTask *(void (^retryBlock)(NSURLSessionDataTask *requestTask, NSError *requestError)) {
343 | return [httpClient POST:apiPath parameters:paramsDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
344 | if ([responseObject isKindOfClass:[NSDictionary class]]){
345 | NSString *jsonStr = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
346 | CFXLog(@"success GET callback\n api request url is %@,\n response data is %@",task.response.URL,jsonStr?:@"");
347 | }
348 | NSDictionary *dic = [responseObject isKindOfClass:[NSDictionary class]] ? responseObject : nil;
349 | CFXSafeBlockRun(succ,dic);
350 | } failure:retryBlock];
351 | } originalFailure:^(NSURLSessionDataTask *failTask, NSError *failError) {
352 | CFXLog(@"api request url is %@,\n response data is %@",failTask.response.URL,failError);
353 | CFXSafeBlockRun(fail,failError);
354 | }];
355 | } else if (type == CFXGetRequestType) {
356 | return [self requestUrlWithAutoRetry:retryCount retryInterval:interval originalRequestCreator:^NSURLSessionDataTask *(void (^retryBlock)(NSURLSessionDataTask *requestTask, NSError *requestError)) {
357 | return [httpClient GET:apiPath parameters:paramsDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
358 | if ([responseObject isKindOfClass:[NSDictionary class]]){
359 | NSString *jsonStr = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
360 | CFXLog(@"success GET callback\n api request url is %@,\n response data is %@",task.response.URL,jsonStr?:@"");
361 | }
362 | NSDictionary *dic = [responseObject isKindOfClass:[NSDictionary class]] ? responseObject : nil;
363 | CFXSafeBlockRun(succ,dic);
364 | } failure:retryBlock];
365 | } originalFailure:^(NSURLSessionDataTask *failTask, NSError *failError) {
366 | CFXLog(@"api request url is %@,\n response data is %@",failTask.response.URL,failError);
367 | CFXSafeBlockRun(fail,failError);
368 | }];
369 | } else {
370 | return nil;
371 | }
372 | }
373 |
374 | #pragma mark - upload files
375 |
376 | - (NSURLSessionUploadTask *)uploadMultiPartFileWithAPIPath:(NSString *)apiPath
377 | params:(NSDictionary *)paramsDic
378 | success:(CFXSuccessRequestAPIBlock)succ
379 | failed:(CFXFailedRequestAPIBlock)fail
380 | autoRetry:(NSUInteger)retryCount
381 | retryInterval:(NSUInteger)interval
382 | timeOut:(NSUInteger)timeOut {
383 |
384 | NSMutableDictionary *dicWithOutUploadKeyValue = [self filterData:paramsDic];
385 | NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:apiPath parameters:dicWithOutUploadKeyValue constructingBodyWithBlock:^(id _Nonnull formData) {
386 | for (NSString *key in [paramsDic allKeys]){
387 | id value = paramsDic[key];
388 | if ([value isKindOfClass:[NSData class]]){
389 | // image/jpeg、text/plain、text/html、application/octet-stream
390 | [formData appendPartWithFileData:value name:key fileName:[NSString stringWithFormat:@"%@.jpg", key] mimeType:@"image/jpeg"];
391 | }
392 | }
393 | } error:nil];
394 |
395 | AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
396 | NSURLSessionUploadTask *uploadtask = [manager
397 | uploadTaskWithStreamedRequest:request
398 | progress:nil
399 | completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
400 | if (error) {
401 | CFXLog(@"api request url is %@,\n response data is %@",response.URL,error);
402 | CFXSafeBlockRun(fail,error);
403 | } else {
404 | CFXLog(@"api request url is %@,\n response data is %@",response.URL,responseObject);
405 | CFXSafeBlockRun(succ,responseObject);
406 | }
407 | }];
408 | [uploadtask resume];
409 |
410 | return uploadtask;
411 | }
412 |
413 | #pragma mark -
414 |
415 | - (id)transferResDataToModel:(NSDictionary *)data {
416 | JSONModel *model;
417 | if (self.modelClassString) {
418 | Class jsonModelClass = NSClassFromString(self.modelClassString);
419 | if (jsonModelClass) {
420 | if (CFXNetworking_isKindOfClass([JSONModel class], jsonModelClass)) {
421 | JSONModelError *err;
422 | model = [[jsonModelClass alloc] initWithDictionary:data error:&err];
423 | CFXLog(@"%ld %@",(long)err.code,err.localizedDescription);
424 | }
425 | }
426 | }
427 | return model;
428 | }
429 |
430 | - (NSError *)checkErrorWithResDic:(NSDictionary *)dic {
431 | if (dic && [dic isKindOfClass:[NSDictionary class]]) {
432 | return nil;
433 | }
434 | NSUInteger errorNo = 10001;
435 | NSString *errorMsg = @"";
436 | NSError *error = [NSError errorWithDomain:@"com.cfx.api"
437 | code:errorNo
438 | userInfo:@{ @"errMsg": errorMsg?:@""}];
439 | return error;
440 | }
441 |
442 | - (NSMutableDictionary *)filterData:(NSDictionary *)originalDic {
443 | if (!originalDic) {
444 | return nil;
445 | }
446 | NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:originalDic];
447 | NSMutableArray *tmArray = [NSMutableArray array];
448 |
449 | for (NSString *key in [tempDic allKeys]){
450 | id value = tempDic[key];
451 | if ([value isKindOfClass:[NSData class]]){
452 | [tmArray addObject:key];
453 | }
454 | }
455 | if ([tmArray count]) {
456 | for (NSString* key in tmArray) {
457 | [tempDic removeObjectForKey:key];
458 | }
459 | }
460 | return tempDic;
461 | }
462 |
463 | @end
464 |
--------------------------------------------------------------------------------
/Example/CPNetwoking.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
11 | 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; };
12 | 6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
13 | 6003F598195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F596195388D20070C39A /* InfoPlist.strings */; };
14 | 6003F59A195388D20070C39A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F599195388D20070C39A /* main.m */; };
15 | 6003F59E195388D20070C39A /* CFXAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F59D195388D20070C39A /* CFXAppDelegate.m */; };
16 | 6003F5A7195388D20070C39A /* CFXViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5A6195388D20070C39A /* CFXViewController.m */; };
17 | 6003F5A9195388D20070C39A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; };
18 | 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; };
19 | 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
20 | 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
21 | 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
22 | 6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
23 | 7C3C7BFB6324C40E6B948F33 /* libPods-CPNetwoking_Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A394AA207276939C4BDEEE7 /* libPods-CPNetwoking_Example.a */; };
24 | 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
25 | 94239964DA5B1C098F536F52 /* libPods-CPNetwoking_Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ABDC2D6A573E18AF3B1A3B8E /* libPods-CPNetwoking_Tests.a */; };
26 | /* End PBXBuildFile section */
27 |
28 | /* Begin PBXContainerItemProxy section */
29 | 6003F5B3195388D20070C39A /* PBXContainerItemProxy */ = {
30 | isa = PBXContainerItemProxy;
31 | containerPortal = 6003F582195388D10070C39A /* Project object */;
32 | proxyType = 1;
33 | remoteGlobalIDString = 6003F589195388D20070C39A;
34 | remoteInfo = CPNetwoking;
35 | };
36 | /* End PBXContainerItemProxy section */
37 |
38 | /* Begin PBXFileReference section */
39 | 3A394AA207276939C4BDEEE7 /* libPods-CPNetwoking_Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CPNetwoking_Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
40 | 3E3A55D94328129412A56FE5 /* CPNetwoking.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CPNetwoking.podspec; path = ../CPNetwoking.podspec; sourceTree = ""; };
41 | 57CF9E37DFEC5104354387B8 /* Pods-CPNetwoking_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CPNetwoking_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CPNetwoking_Tests/Pods-CPNetwoking_Tests.debug.xcconfig"; sourceTree = ""; };
42 | 6003F58A195388D20070C39A /* CPNetwoking_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CPNetwoking_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
43 | 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
44 | 6003F58F195388D20070C39A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
45 | 6003F591195388D20070C39A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
46 | 6003F595195388D20070C39A /* CPNetwoking-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CPNetwoking-Info.plist"; sourceTree = ""; };
47 | 6003F597195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
48 | 6003F599195388D20070C39A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
49 | 6003F59B195388D20070C39A /* CPNetwoking-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CPNetwoking-Prefix.pch"; sourceTree = ""; };
50 | 6003F59C195388D20070C39A /* CFXAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CFXAppDelegate.h; sourceTree = ""; };
51 | 6003F59D195388D20070C39A /* CFXAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CFXAppDelegate.m; sourceTree = ""; };
52 | 6003F5A5195388D20070C39A /* CFXViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CFXViewController.h; sourceTree = ""; };
53 | 6003F5A6195388D20070C39A /* CFXViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CFXViewController.m; sourceTree = ""; };
54 | 6003F5A8195388D20070C39A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
55 | 6003F5AE195388D20070C39A /* CPNetwoking_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CPNetwoking_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
56 | 6003F5AF195388D20070C39A /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
57 | 6003F5B7195388D20070C39A /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; };
58 | 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
59 | 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; };
60 | 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; };
61 | 7D47D2EA1176B15C889749E8 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; };
62 | 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; };
63 | 99D78E79E4BBEF3C5B588539 /* Pods-CPNetwoking_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CPNetwoking_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-CPNetwoking_Example/Pods-CPNetwoking_Example.release.xcconfig"; sourceTree = ""; };
64 | AAFB9657EED070071C788FF9 /* Pods-CPNetwoking_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CPNetwoking_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CPNetwoking_Tests/Pods-CPNetwoking_Tests.release.xcconfig"; sourceTree = ""; };
65 | ABDC2D6A573E18AF3B1A3B8E /* libPods-CPNetwoking_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CPNetwoking_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
66 | BC9C20C1C09CEEC4C60CED78 /* Pods-CPNetwoking_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CPNetwoking_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CPNetwoking_Example/Pods-CPNetwoking_Example.debug.xcconfig"; sourceTree = ""; };
67 | D951AFBE89383884000BB099 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; };
68 | /* End PBXFileReference section */
69 |
70 | /* Begin PBXFrameworksBuildPhase section */
71 | 6003F587195388D20070C39A /* Frameworks */ = {
72 | isa = PBXFrameworksBuildPhase;
73 | buildActionMask = 2147483647;
74 | files = (
75 | 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */,
76 | 6003F592195388D20070C39A /* UIKit.framework in Frameworks */,
77 | 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */,
78 | 7C3C7BFB6324C40E6B948F33 /* libPods-CPNetwoking_Example.a in Frameworks */,
79 | );
80 | runOnlyForDeploymentPostprocessing = 0;
81 | };
82 | 6003F5AB195388D20070C39A /* Frameworks */ = {
83 | isa = PBXFrameworksBuildPhase;
84 | buildActionMask = 2147483647;
85 | files = (
86 | 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */,
87 | 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */,
88 | 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */,
89 | 94239964DA5B1C098F536F52 /* libPods-CPNetwoking_Tests.a in Frameworks */,
90 | );
91 | runOnlyForDeploymentPostprocessing = 0;
92 | };
93 | /* End PBXFrameworksBuildPhase section */
94 |
95 | /* Begin PBXGroup section */
96 | 6003F581195388D10070C39A = {
97 | isa = PBXGroup;
98 | children = (
99 | 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */,
100 | 6003F593195388D20070C39A /* Example for CPNetwoking */,
101 | 6003F5B5195388D20070C39A /* Tests */,
102 | 6003F58C195388D20070C39A /* Frameworks */,
103 | 6003F58B195388D20070C39A /* Products */,
104 | 6E303EBDB5E3B78BF297F7E6 /* Pods */,
105 | );
106 | sourceTree = "";
107 | };
108 | 6003F58B195388D20070C39A /* Products */ = {
109 | isa = PBXGroup;
110 | children = (
111 | 6003F58A195388D20070C39A /* CPNetwoking_Example.app */,
112 | 6003F5AE195388D20070C39A /* CPNetwoking_Tests.xctest */,
113 | );
114 | name = Products;
115 | sourceTree = "";
116 | };
117 | 6003F58C195388D20070C39A /* Frameworks */ = {
118 | isa = PBXGroup;
119 | children = (
120 | 6003F58D195388D20070C39A /* Foundation.framework */,
121 | 6003F58F195388D20070C39A /* CoreGraphics.framework */,
122 | 6003F591195388D20070C39A /* UIKit.framework */,
123 | 6003F5AF195388D20070C39A /* XCTest.framework */,
124 | 3A394AA207276939C4BDEEE7 /* libPods-CPNetwoking_Example.a */,
125 | ABDC2D6A573E18AF3B1A3B8E /* libPods-CPNetwoking_Tests.a */,
126 | );
127 | name = Frameworks;
128 | sourceTree = "";
129 | };
130 | 6003F593195388D20070C39A /* Example for CPNetwoking */ = {
131 | isa = PBXGroup;
132 | children = (
133 | 6003F59C195388D20070C39A /* CFXAppDelegate.h */,
134 | 6003F59D195388D20070C39A /* CFXAppDelegate.m */,
135 | 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */,
136 | 6003F5A5195388D20070C39A /* CFXViewController.h */,
137 | 6003F5A6195388D20070C39A /* CFXViewController.m */,
138 | 6003F5A8195388D20070C39A /* Images.xcassets */,
139 | 6003F594195388D20070C39A /* Supporting Files */,
140 | );
141 | name = "Example for CPNetwoking";
142 | path = CPNetwoking;
143 | sourceTree = "";
144 | };
145 | 6003F594195388D20070C39A /* Supporting Files */ = {
146 | isa = PBXGroup;
147 | children = (
148 | 6003F595195388D20070C39A /* CPNetwoking-Info.plist */,
149 | 6003F596195388D20070C39A /* InfoPlist.strings */,
150 | 6003F599195388D20070C39A /* main.m */,
151 | 6003F59B195388D20070C39A /* CPNetwoking-Prefix.pch */,
152 | );
153 | name = "Supporting Files";
154 | sourceTree = "";
155 | };
156 | 6003F5B5195388D20070C39A /* Tests */ = {
157 | isa = PBXGroup;
158 | children = (
159 | 6003F5BB195388D20070C39A /* Tests.m */,
160 | 6003F5B6195388D20070C39A /* Supporting Files */,
161 | );
162 | path = Tests;
163 | sourceTree = "";
164 | };
165 | 6003F5B6195388D20070C39A /* Supporting Files */ = {
166 | isa = PBXGroup;
167 | children = (
168 | 6003F5B7195388D20070C39A /* Tests-Info.plist */,
169 | 6003F5B8195388D20070C39A /* InfoPlist.strings */,
170 | 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */,
171 | );
172 | name = "Supporting Files";
173 | sourceTree = "";
174 | };
175 | 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */ = {
176 | isa = PBXGroup;
177 | children = (
178 | 3E3A55D94328129412A56FE5 /* CPNetwoking.podspec */,
179 | 7D47D2EA1176B15C889749E8 /* README.md */,
180 | D951AFBE89383884000BB099 /* LICENSE */,
181 | );
182 | name = "Podspec Metadata";
183 | sourceTree = "";
184 | };
185 | 6E303EBDB5E3B78BF297F7E6 /* Pods */ = {
186 | isa = PBXGroup;
187 | children = (
188 | BC9C20C1C09CEEC4C60CED78 /* Pods-CPNetwoking_Example.debug.xcconfig */,
189 | 99D78E79E4BBEF3C5B588539 /* Pods-CPNetwoking_Example.release.xcconfig */,
190 | 57CF9E37DFEC5104354387B8 /* Pods-CPNetwoking_Tests.debug.xcconfig */,
191 | AAFB9657EED070071C788FF9 /* Pods-CPNetwoking_Tests.release.xcconfig */,
192 | );
193 | name = Pods;
194 | sourceTree = "";
195 | };
196 | /* End PBXGroup section */
197 |
198 | /* Begin PBXNativeTarget section */
199 | 6003F589195388D20070C39A /* CPNetwoking_Example */ = {
200 | isa = PBXNativeTarget;
201 | buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "CPNetwoking_Example" */;
202 | buildPhases = (
203 | 2096B603AEA872AC299D6BEB /* [CP] Check Pods Manifest.lock */,
204 | 6003F586195388D20070C39A /* Sources */,
205 | 6003F587195388D20070C39A /* Frameworks */,
206 | 6003F588195388D20070C39A /* Resources */,
207 | C6FBF1E07C7ED9D12F7F6784 /* [CP] Embed Pods Frameworks */,
208 | C80B5E50DC7DF7B43A3DAEBB /* [CP] Copy Pods Resources */,
209 | );
210 | buildRules = (
211 | );
212 | dependencies = (
213 | );
214 | name = CPNetwoking_Example;
215 | productName = CPNetwoking;
216 | productReference = 6003F58A195388D20070C39A /* CPNetwoking_Example.app */;
217 | productType = "com.apple.product-type.application";
218 | };
219 | 6003F5AD195388D20070C39A /* CPNetwoking_Tests */ = {
220 | isa = PBXNativeTarget;
221 | buildConfigurationList = 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "CPNetwoking_Tests" */;
222 | buildPhases = (
223 | EEED3362D390238EA433DFB2 /* [CP] Check Pods Manifest.lock */,
224 | 6003F5AA195388D20070C39A /* Sources */,
225 | 6003F5AB195388D20070C39A /* Frameworks */,
226 | 6003F5AC195388D20070C39A /* Resources */,
227 | 866D21B68F39EDFD25E29DA7 /* [CP] Embed Pods Frameworks */,
228 | 773FD8802F54598D3F96BE9A /* [CP] Copy Pods Resources */,
229 | );
230 | buildRules = (
231 | );
232 | dependencies = (
233 | 6003F5B4195388D20070C39A /* PBXTargetDependency */,
234 | );
235 | name = CPNetwoking_Tests;
236 | productName = CPNetwokingTests;
237 | productReference = 6003F5AE195388D20070C39A /* CPNetwoking_Tests.xctest */;
238 | productType = "com.apple.product-type.bundle.unit-test";
239 | };
240 | /* End PBXNativeTarget section */
241 |
242 | /* Begin PBXProject section */
243 | 6003F582195388D10070C39A /* Project object */ = {
244 | isa = PBXProject;
245 | attributes = {
246 | CLASSPREFIX = CFX;
247 | LastUpgradeCheck = 0800;
248 | ORGANIZATIONNAME = xiaochengfei;
249 | TargetAttributes = {
250 | 6003F589195388D20070C39A = {
251 | ProvisioningStyle = Manual;
252 | };
253 | 6003F5AD195388D20070C39A = {
254 | TestTargetID = 6003F589195388D20070C39A;
255 | };
256 | };
257 | };
258 | buildConfigurationList = 6003F585195388D10070C39A /* Build configuration list for PBXProject "CPNetwoking" */;
259 | compatibilityVersion = "Xcode 3.2";
260 | developmentRegion = English;
261 | hasScannedForEncodings = 0;
262 | knownRegions = (
263 | en,
264 | Base,
265 | );
266 | mainGroup = 6003F581195388D10070C39A;
267 | productRefGroup = 6003F58B195388D20070C39A /* Products */;
268 | projectDirPath = "";
269 | projectRoot = "";
270 | targets = (
271 | 6003F589195388D20070C39A /* CPNetwoking_Example */,
272 | 6003F5AD195388D20070C39A /* CPNetwoking_Tests */,
273 | );
274 | };
275 | /* End PBXProject section */
276 |
277 | /* Begin PBXResourcesBuildPhase section */
278 | 6003F588195388D20070C39A /* Resources */ = {
279 | isa = PBXResourcesBuildPhase;
280 | buildActionMask = 2147483647;
281 | files = (
282 | 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */,
283 | 6003F5A9195388D20070C39A /* Images.xcassets in Resources */,
284 | 6003F598195388D20070C39A /* InfoPlist.strings in Resources */,
285 | );
286 | runOnlyForDeploymentPostprocessing = 0;
287 | };
288 | 6003F5AC195388D20070C39A /* Resources */ = {
289 | isa = PBXResourcesBuildPhase;
290 | buildActionMask = 2147483647;
291 | files = (
292 | 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */,
293 | );
294 | runOnlyForDeploymentPostprocessing = 0;
295 | };
296 | /* End PBXResourcesBuildPhase section */
297 |
298 | /* Begin PBXShellScriptBuildPhase section */
299 | 2096B603AEA872AC299D6BEB /* [CP] Check Pods Manifest.lock */ = {
300 | isa = PBXShellScriptBuildPhase;
301 | buildActionMask = 2147483647;
302 | files = (
303 | );
304 | inputPaths = (
305 | );
306 | name = "[CP] Check Pods Manifest.lock";
307 | outputPaths = (
308 | );
309 | runOnlyForDeploymentPostprocessing = 0;
310 | shellPath = /bin/sh;
311 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
312 | showEnvVarsInLog = 0;
313 | };
314 | 773FD8802F54598D3F96BE9A /* [CP] Copy Pods Resources */ = {
315 | isa = PBXShellScriptBuildPhase;
316 | buildActionMask = 2147483647;
317 | files = (
318 | );
319 | inputPaths = (
320 | );
321 | name = "[CP] Copy Pods Resources";
322 | outputPaths = (
323 | );
324 | runOnlyForDeploymentPostprocessing = 0;
325 | shellPath = /bin/sh;
326 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CPNetwoking_Tests/Pods-CPNetwoking_Tests-resources.sh\"\n";
327 | showEnvVarsInLog = 0;
328 | };
329 | 866D21B68F39EDFD25E29DA7 /* [CP] Embed Pods Frameworks */ = {
330 | isa = PBXShellScriptBuildPhase;
331 | buildActionMask = 2147483647;
332 | files = (
333 | );
334 | inputPaths = (
335 | );
336 | name = "[CP] Embed Pods Frameworks";
337 | outputPaths = (
338 | );
339 | runOnlyForDeploymentPostprocessing = 0;
340 | shellPath = /bin/sh;
341 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CPNetwoking_Tests/Pods-CPNetwoking_Tests-frameworks.sh\"\n";
342 | showEnvVarsInLog = 0;
343 | };
344 | C6FBF1E07C7ED9D12F7F6784 /* [CP] Embed Pods Frameworks */ = {
345 | isa = PBXShellScriptBuildPhase;
346 | buildActionMask = 2147483647;
347 | files = (
348 | );
349 | inputPaths = (
350 | );
351 | name = "[CP] Embed Pods Frameworks";
352 | outputPaths = (
353 | );
354 | runOnlyForDeploymentPostprocessing = 0;
355 | shellPath = /bin/sh;
356 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CPNetwoking_Example/Pods-CPNetwoking_Example-frameworks.sh\"\n";
357 | showEnvVarsInLog = 0;
358 | };
359 | C80B5E50DC7DF7B43A3DAEBB /* [CP] Copy Pods Resources */ = {
360 | isa = PBXShellScriptBuildPhase;
361 | buildActionMask = 2147483647;
362 | files = (
363 | );
364 | inputPaths = (
365 | );
366 | name = "[CP] Copy Pods Resources";
367 | outputPaths = (
368 | );
369 | runOnlyForDeploymentPostprocessing = 0;
370 | shellPath = /bin/sh;
371 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CPNetwoking_Example/Pods-CPNetwoking_Example-resources.sh\"\n";
372 | showEnvVarsInLog = 0;
373 | };
374 | EEED3362D390238EA433DFB2 /* [CP] Check Pods Manifest.lock */ = {
375 | isa = PBXShellScriptBuildPhase;
376 | buildActionMask = 2147483647;
377 | files = (
378 | );
379 | inputPaths = (
380 | );
381 | name = "[CP] Check Pods Manifest.lock";
382 | outputPaths = (
383 | );
384 | runOnlyForDeploymentPostprocessing = 0;
385 | shellPath = /bin/sh;
386 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
387 | showEnvVarsInLog = 0;
388 | };
389 | /* End PBXShellScriptBuildPhase section */
390 |
391 | /* Begin PBXSourcesBuildPhase section */
392 | 6003F586195388D20070C39A /* Sources */ = {
393 | isa = PBXSourcesBuildPhase;
394 | buildActionMask = 2147483647;
395 | files = (
396 | 6003F59E195388D20070C39A /* CFXAppDelegate.m in Sources */,
397 | 6003F5A7195388D20070C39A /* CFXViewController.m in Sources */,
398 | 6003F59A195388D20070C39A /* main.m in Sources */,
399 | );
400 | runOnlyForDeploymentPostprocessing = 0;
401 | };
402 | 6003F5AA195388D20070C39A /* Sources */ = {
403 | isa = PBXSourcesBuildPhase;
404 | buildActionMask = 2147483647;
405 | files = (
406 | 6003F5BC195388D20070C39A /* Tests.m in Sources */,
407 | );
408 | runOnlyForDeploymentPostprocessing = 0;
409 | };
410 | /* End PBXSourcesBuildPhase section */
411 |
412 | /* Begin PBXTargetDependency section */
413 | 6003F5B4195388D20070C39A /* PBXTargetDependency */ = {
414 | isa = PBXTargetDependency;
415 | target = 6003F589195388D20070C39A /* CPNetwoking_Example */;
416 | targetProxy = 6003F5B3195388D20070C39A /* PBXContainerItemProxy */;
417 | };
418 | /* End PBXTargetDependency section */
419 |
420 | /* Begin PBXVariantGroup section */
421 | 6003F596195388D20070C39A /* InfoPlist.strings */ = {
422 | isa = PBXVariantGroup;
423 | children = (
424 | 6003F597195388D20070C39A /* en */,
425 | );
426 | name = InfoPlist.strings;
427 | sourceTree = "";
428 | };
429 | 6003F5B8195388D20070C39A /* InfoPlist.strings */ = {
430 | isa = PBXVariantGroup;
431 | children = (
432 | 6003F5B9195388D20070C39A /* en */,
433 | );
434 | name = InfoPlist.strings;
435 | sourceTree = "";
436 | };
437 | /* End PBXVariantGroup section */
438 |
439 | /* Begin XCBuildConfiguration section */
440 | 6003F5BD195388D20070C39A /* Debug */ = {
441 | isa = XCBuildConfiguration;
442 | buildSettings = {
443 | ALWAYS_SEARCH_USER_PATHS = NO;
444 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
445 | CLANG_CXX_LIBRARY = "libc++";
446 | CLANG_ENABLE_MODULES = YES;
447 | CLANG_ENABLE_OBJC_ARC = YES;
448 | CLANG_WARN_BOOL_CONVERSION = YES;
449 | CLANG_WARN_CONSTANT_CONVERSION = YES;
450 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
451 | CLANG_WARN_EMPTY_BODY = YES;
452 | CLANG_WARN_ENUM_CONVERSION = YES;
453 | CLANG_WARN_INFINITE_RECURSION = YES;
454 | CLANG_WARN_INT_CONVERSION = YES;
455 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
456 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
457 | CLANG_WARN_UNREACHABLE_CODE = YES;
458 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
459 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
460 | COPY_PHASE_STRIP = NO;
461 | ENABLE_STRICT_OBJC_MSGSEND = YES;
462 | ENABLE_TESTABILITY = YES;
463 | GCC_C_LANGUAGE_STANDARD = gnu99;
464 | GCC_DYNAMIC_NO_PIC = NO;
465 | GCC_NO_COMMON_BLOCKS = YES;
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_INFINITE_RECURSION = YES;
499 | CLANG_WARN_INT_CONVERSION = YES;
500 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
501 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
502 | CLANG_WARN_UNREACHABLE_CODE = YES;
503 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
504 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
505 | COPY_PHASE_STRIP = YES;
506 | ENABLE_NS_ASSERTIONS = NO;
507 | ENABLE_STRICT_OBJC_MSGSEND = YES;
508 | GCC_C_LANGUAGE_STANDARD = gnu99;
509 | GCC_NO_COMMON_BLOCKS = YES;
510 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
511 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
512 | GCC_WARN_UNDECLARED_SELECTOR = YES;
513 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
514 | GCC_WARN_UNUSED_FUNCTION = YES;
515 | GCC_WARN_UNUSED_VARIABLE = YES;
516 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
517 | SDKROOT = iphoneos;
518 | TARGETED_DEVICE_FAMILY = "1,2";
519 | VALIDATE_PRODUCT = YES;
520 | };
521 | name = Release;
522 | };
523 | 6003F5C0195388D20070C39A /* Debug */ = {
524 | isa = XCBuildConfiguration;
525 | baseConfigurationReference = BC9C20C1C09CEEC4C60CED78 /* Pods-CPNetwoking_Example.debug.xcconfig */;
526 | buildSettings = {
527 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
528 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
529 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
530 | DEVELOPMENT_TEAM = "";
531 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
532 | GCC_PREFIX_HEADER = "CPNetwoking/CPNetwoking-Prefix.pch";
533 | INFOPLIST_FILE = "CPNetwoking/CPNetwoking-Info.plist";
534 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
535 | MODULE_NAME = ExampleApp;
536 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
537 | PRODUCT_NAME = "$(TARGET_NAME)";
538 | WRAPPER_EXTENSION = app;
539 | };
540 | name = Debug;
541 | };
542 | 6003F5C1195388D20070C39A /* Release */ = {
543 | isa = XCBuildConfiguration;
544 | baseConfigurationReference = 99D78E79E4BBEF3C5B588539 /* Pods-CPNetwoking_Example.release.xcconfig */;
545 | buildSettings = {
546 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
547 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
548 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
549 | DEVELOPMENT_TEAM = "";
550 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
551 | GCC_PREFIX_HEADER = "CPNetwoking/CPNetwoking-Prefix.pch";
552 | INFOPLIST_FILE = "CPNetwoking/CPNetwoking-Info.plist";
553 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
554 | MODULE_NAME = ExampleApp;
555 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
556 | PRODUCT_NAME = "$(TARGET_NAME)";
557 | WRAPPER_EXTENSION = app;
558 | };
559 | name = Release;
560 | };
561 | 6003F5C3195388D20070C39A /* Debug */ = {
562 | isa = XCBuildConfiguration;
563 | baseConfigurationReference = 57CF9E37DFEC5104354387B8 /* Pods-CPNetwoking_Tests.debug.xcconfig */;
564 | buildSettings = {
565 | BUNDLE_LOADER = "$(TEST_HOST)";
566 | FRAMEWORK_SEARCH_PATHS = (
567 | "$(SDKROOT)/Developer/Library/Frameworks",
568 | "$(inherited)",
569 | "$(DEVELOPER_FRAMEWORKS_DIR)",
570 | );
571 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
572 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
573 | GCC_PREPROCESSOR_DEFINITIONS = (
574 | "DEBUG=1",
575 | "$(inherited)",
576 | );
577 | INFOPLIST_FILE = "Tests/Tests-Info.plist";
578 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
579 | PRODUCT_NAME = "$(TARGET_NAME)";
580 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CPNetwoking_Example.app/CPNetwoking_Example";
581 | WRAPPER_EXTENSION = xctest;
582 | };
583 | name = Debug;
584 | };
585 | 6003F5C4195388D20070C39A /* Release */ = {
586 | isa = XCBuildConfiguration;
587 | baseConfigurationReference = AAFB9657EED070071C788FF9 /* Pods-CPNetwoking_Tests.release.xcconfig */;
588 | buildSettings = {
589 | BUNDLE_LOADER = "$(TEST_HOST)";
590 | FRAMEWORK_SEARCH_PATHS = (
591 | "$(SDKROOT)/Developer/Library/Frameworks",
592 | "$(inherited)",
593 | "$(DEVELOPER_FRAMEWORKS_DIR)",
594 | );
595 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
596 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
597 | INFOPLIST_FILE = "Tests/Tests-Info.plist";
598 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
599 | PRODUCT_NAME = "$(TARGET_NAME)";
600 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CPNetwoking_Example.app/CPNetwoking_Example";
601 | WRAPPER_EXTENSION = xctest;
602 | };
603 | name = Release;
604 | };
605 | /* End XCBuildConfiguration section */
606 |
607 | /* Begin XCConfigurationList section */
608 | 6003F585195388D10070C39A /* Build configuration list for PBXProject "CPNetwoking" */ = {
609 | isa = XCConfigurationList;
610 | buildConfigurations = (
611 | 6003F5BD195388D20070C39A /* Debug */,
612 | 6003F5BE195388D20070C39A /* Release */,
613 | );
614 | defaultConfigurationIsVisible = 0;
615 | defaultConfigurationName = Release;
616 | };
617 | 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "CPNetwoking_Example" */ = {
618 | isa = XCConfigurationList;
619 | buildConfigurations = (
620 | 6003F5C0195388D20070C39A /* Debug */,
621 | 6003F5C1195388D20070C39A /* Release */,
622 | );
623 | defaultConfigurationIsVisible = 0;
624 | defaultConfigurationName = Release;
625 | };
626 | 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "CPNetwoking_Tests" */ = {
627 | isa = XCConfigurationList;
628 | buildConfigurations = (
629 | 6003F5C3195388D20070C39A /* Debug */,
630 | 6003F5C4195388D20070C39A /* Release */,
631 | );
632 | defaultConfigurationIsVisible = 0;
633 | defaultConfigurationName = Release;
634 | };
635 | /* End XCConfigurationList section */
636 | };
637 | rootObject = 6003F582195388D10070C39A /* Project object */;
638 | }
639 |
--------------------------------------------------------------------------------