├── .DS_Store ├── .gitignore ├── .travis.yml ├── AFNetworking ├── AFHTTPSessionManager.h ├── AFHTTPSessionManager.m ├── AFNetworkReachabilityManager.h ├── AFNetworkReachabilityManager.m ├── AFNetworking.h ├── AFSecurityPolicy.h ├── AFSecurityPolicy.m ├── AFURLRequestSerialization.h ├── AFURLRequestSerialization.m ├── AFURLResponseSerialization.h ├── AFURLResponseSerialization.m ├── AFURLSessionManager.h └── AFURLSessionManager.m ├── BGNetwork.podspec ├── BGNetwork.podspec.json ├── BGNetwork.podspec.json.bak ├── BGNetwork ├── BGAFHTTPClient.h ├── BGAFHTTPClient.m ├── BGAFRequestSerializer.h ├── BGAFRequestSerializer.m ├── BGAFResponseSerializer.h ├── BGAFResponseSerializer.m ├── BGBatchRequest.h ├── BGBatchRequest.m ├── BGDownloadRequest.h ├── BGDownloadRequest.m ├── BGNetwork.h ├── BGNetworkCache.h ├── BGNetworkCache.m ├── BGNetworkConfiguration.h ├── BGNetworkConfiguration.m ├── BGNetworkManager.h ├── BGNetworkManager.m ├── BGNetworkRequest.h ├── BGNetworkRequest.m ├── BGUploadRequest.h ├── BGUploadRequest.m ├── BGUtilFunction.h └── BGUtilFunction.m ├── BGNetworkDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata ├── xcshareddata │ └── xcschemes │ │ └── BGNetworkDemo.xcscheme └── xcuserdata │ └── user.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── BGNetworkDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ └── LaunchScreen.xib ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── M13ProgressSuite │ ├── Console │ │ ├── M13ProgressConsole.h │ │ └── M13ProgressConsole.m │ ├── HUD │ │ ├── M13ProgressHUD.h │ │ ├── M13ProgressHUD.m │ │ ├── UIImage+ImageEffects.h │ │ └── UIImage+ImageEffects.m │ ├── NavigationController │ │ ├── UINavigationController+M13ProgressViewBar.h │ │ └── UINavigationController+M13ProgressViewBar.m │ └── ProgressViews │ │ ├── M13ProgressView.h │ │ ├── M13ProgressView.m │ │ ├── M13ProgressViewBar.h │ │ ├── M13ProgressViewBar.m │ │ ├── M13ProgressViewBorderedBar.h │ │ ├── M13ProgressViewBorderedBar.m │ │ ├── M13ProgressViewFilteredImage.h │ │ ├── M13ProgressViewFilteredImage.m │ │ ├── M13ProgressViewImage.h │ │ ├── M13ProgressViewImage.m │ │ ├── M13ProgressViewLetterpress.h │ │ ├── M13ProgressViewLetterpress.m │ │ ├── M13ProgressViewMetro.h │ │ ├── M13ProgressViewMetro.m │ │ ├── M13ProgressViewMetroDotPolygon.h │ │ ├── M13ProgressViewMetroDotPolygon.m │ │ ├── M13ProgressViewPie.h │ │ ├── M13ProgressViewPie.m │ │ ├── M13ProgressViewRadiative.h │ │ ├── M13ProgressViewRadiative.m │ │ ├── M13ProgressViewRing.h │ │ ├── M13ProgressViewRing.m │ │ ├── M13ProgressViewSegmentedBar.h │ │ ├── M13ProgressViewSegmentedBar.m │ │ ├── M13ProgressViewSegmentedRing.h │ │ ├── M13ProgressViewSegmentedRing.m │ │ ├── M13ProgressViewStripedBar.h │ │ └── M13ProgressViewStripedBar.m ├── Macro │ └── LayoutMacro.h ├── Main.storyboard ├── Models │ ├── Base │ │ ├── BaseModel.h │ │ ├── BaseModel.m │ │ └── Jastor │ │ │ ├── Jastor-Prefix.pch │ │ │ ├── Jastor.h │ │ │ ├── Jastor.m │ │ │ ├── JastorRuntimeHelper.h │ │ │ └── JastorRuntimeHelper.m │ └── Demo │ │ ├── DemoModel.h │ │ ├── DemoModel.m │ │ ├── PageModel.h │ │ └── PageModel.m ├── Network │ ├── AdvertInfoRequest.h │ ├── AdvertInfoRequest.m │ ├── DemoNetworkConfiguration.h │ ├── DemoNetworkConfiguration.m │ ├── DemoRequest.h │ ├── DemoRequest.m │ ├── DownloadFileRequest.h │ ├── DownloadFileRequest.m │ ├── InfoRequest.h │ └── InfoRequest.m ├── Resource │ └── icon_shanchu@2x.png ├── SDWebImage │ ├── MKAnnotationView+WebCache.h │ ├── MKAnnotationView+WebCache.m │ ├── NSData+ImageContentType.h │ ├── NSData+ImageContentType.m │ ├── SDImageCache.h │ ├── SDImageCache.m │ ├── SDWebImageCompat.h │ ├── SDWebImageCompat.m │ ├── SDWebImageDecoder.h │ ├── SDWebImageDecoder.m │ ├── SDWebImageDownloader.h │ ├── SDWebImageDownloader.m │ ├── SDWebImageDownloaderOperation.h │ ├── SDWebImageDownloaderOperation.m │ ├── SDWebImageManager.h │ ├── SDWebImageManager.m │ ├── SDWebImageOperation.h │ ├── SDWebImagePrefetcher.h │ ├── SDWebImagePrefetcher.m │ ├── UIButton+WebCache.h │ ├── UIButton+WebCache.m │ ├── UIImage+GIF.h │ ├── UIImage+GIF.m │ ├── UIImage+MultiFormat.h │ ├── UIImage+MultiFormat.m │ ├── UIImage+WebP.h │ ├── UIImage+WebP.m │ ├── UIImageView+HighlightedWebCache.h │ ├── UIImageView+HighlightedWebCache.m │ ├── UIImageView+WebCache.h │ ├── UIImageView+WebCache.m │ ├── UIView+WebCacheOperation.h │ └── UIView+WebCacheOperation.m ├── UIView+Extra.h ├── UIView+Extra.m ├── ViewController │ ├── Base │ │ ├── BaseViewController.h │ │ └── BaseViewController.m │ └── Demo │ │ ├── BGBatchViewController.h │ │ ├── BGBatchViewController.m │ │ ├── BGBatchViewController.xib │ │ ├── BGDownloadRequestController.h │ │ ├── BGDownloadRequestController.m │ │ ├── BGDownloadRequestController.xib │ │ ├── BGUploadViewController.h │ │ ├── BGUploadViewController.m │ │ ├── BGUploadViewController.xib │ │ ├── TableViewController.h │ │ ├── TableViewController.m │ │ ├── ViewController.h │ │ └── ViewController.m ├── Views │ ├── Base │ │ ├── BaseCell.h │ │ ├── BaseCell.m │ │ ├── BaseCollectionViewCell.h │ │ ├── BaseCollectionViewCell.m │ │ ├── BaseDoubleLineCell.h │ │ ├── BaseDoubleLineCell.m │ │ ├── BaseDoubleLineView.h │ │ ├── BaseDoubleLineView.m │ │ ├── BaseLineCell.h │ │ ├── BaseLineCell.m │ │ ├── BaseLineCell.xib │ │ ├── BaseLineView.h │ │ ├── BaseLineView.m │ │ ├── BaseView.h │ │ └── BaseView.m │ ├── Demo │ │ ├── DemoCell.h │ │ ├── DemoCell.m │ │ └── DemoCell.xib │ ├── POrderInfoCell.xib │ └── RefreshTableView │ │ ├── RefreshConstant.h │ │ ├── RefreshTableView.h │ │ ├── RefreshTableView.m │ │ ├── RefreshTimeHelper.h │ │ ├── RefreshTimeHelper.m │ │ ├── Resource │ │ ├── _refresh_arrow@2x.png │ │ └── _refresh_rotate@2x.png │ │ └── Source │ │ ├── RefreshTableFooterView.h │ │ ├── RefreshTableFooterView.m │ │ ├── RefreshTableFooterView.xib │ │ ├── RefreshTableHeaderView.h │ │ └── RefreshTableHeaderView.m ├── casetree.cer ├── main.m └── server.crt ├── BGNetworkDemoTests ├── BGNetworkDemoTests.m └── Info.plist ├── LICENSE ├── README.md └── assets └── architecture.png /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuchungui/BGNetwork/a1345c50735e73d7bf6d9c9627731fe1fcc8bcee/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | Breakpoints_v2.xcbkptlist 28 | .DS_Store 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode7.1 3 | script: xctool -project BGNetworkDemo.xcodeproj -scheme BGNetworkDemo build test -sdk iphonesimulator GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES 4 | after_success: 5 | - bash <(curl -s https://codecov.io/bash) 6 | -------------------------------------------------------------------------------- /AFNetworking/AFNetworking.h: -------------------------------------------------------------------------------- 1 | // AFNetworking.h 2 | // 3 | // Copyright (c) 2013 AFNetworking (http://afnetworking.com/) 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 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import 25 | #import 26 | 27 | #ifndef _AFNETWORKING_ 28 | #define _AFNETWORKING_ 29 | 30 | #import "AFURLRequestSerialization.h" 31 | #import "AFURLResponseSerialization.h" 32 | #import "AFSecurityPolicy.h" 33 | 34 | #if !TARGET_OS_WATCH 35 | #import "AFNetworkReachabilityManager.h" 36 | #endif 37 | 38 | #import "AFURLSessionManager.h" 39 | #import "AFHTTPSessionManager.h" 40 | 41 | #endif /* _AFNETWORKING_ */ 42 | -------------------------------------------------------------------------------- /BGNetwork.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = 'BGNetwork' 3 | spec.version = '0.2.6' 4 | spec.license = 'MIT' 5 | spec.summary = 'BGNetwork is a request util based on AFNetworking' 6 | spec.homepage = 'https://github.com/liuchungui/BGNetwork' 7 | spec.author = { "liuchungui": "404468494@qq.com", "blog": "http://www.liuchungui.com"} 8 | spec.source = { :git => 'https://github.com/chunguiLiu/BGNetwork.git', :tag => spec.version } 9 | spec.source_files = "BGNetwork/*" 10 | spec.platform = :ios, '7.0' 11 | spec.requires_arc = true 12 | spec.dependency 'AFNetworking', '~> 3.0.2' 13 | 14 | #指定xcode编译配置 15 | spec.xcconfig = { 16 | 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' 17 | } 18 | end 19 | -------------------------------------------------------------------------------- /BGNetwork.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BGNetwork", 3 | "version": "0.2.5", 4 | "license": "MIT", 5 | "summary": "BGNetwork is a request util based on AFNetworking", 6 | "homepage": "https://github.com/chunguiLiu/BGNetwork", 7 | "authors": { 8 | "liuchungui": "404468494@qq.com", 9 | "blog": "http://www.liuchungui.com" 10 | }, 11 | "source": { 12 | "git": "https://github.com/chunguiLiu/BGNetwork.git", 13 | "tag": "0.2.3" 14 | }, 15 | "source_files": "BGNetwork/*", 16 | "platforms": { 17 | "ios": "7.0" 18 | }, 19 | "requires_arc": true, 20 | "dependencies": { 21 | "AFNetworking": [ 22 | "~> 3.0.2" 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BGNetwork.podspec.json.bak: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BGNetwork", 3 | "version": "0.2.4", 4 | "license": "MIT", 5 | "summary": "BGNetwork is a request util based on AFNetworking", 6 | "homepage": "https://github.com/chunguiLiu/BGNetwork", 7 | "authors": { 8 | "liuchungui": "404468494@qq.com", 9 | "blog": "http://www.liuchungui.com" 10 | }, 11 | "source": { 12 | "git": "https://github.com/chunguiLiu/BGNetwork.git", 13 | "tag": "0.2.3" 14 | }, 15 | "source_files": "BGNetwork/*", 16 | "platforms": { 17 | "ios": "7.0" 18 | }, 19 | "requires_arc": true, 20 | "dependencies": { 21 | "AFNetworking": [ 22 | "~> 3.0.2" 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BGNetwork/BGAFHTTPClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGAFHTTPClient.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/19. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "AFHTTPSessionManager.h" 10 | 11 | @interface BGAFHTTPClient : AFHTTPSessionManager 12 | /** 判断一组请求是否已经请求完成 */ 13 | - (BOOL)isHttpQueueFinished:( NSArray * _Nonnull )httpUrlArray; 14 | 15 | /** 取消请求 */ 16 | - (void)cancelTasksWithUrl:( NSString * _Nonnull )url; 17 | @end 18 | -------------------------------------------------------------------------------- /BGNetwork/BGAFHTTPClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGAFHTTPClient.m 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/19. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGAFHTTPClient.h" 10 | 11 | @implementation BGAFHTTPClient 12 | - (id)initWithBaseURL:(NSURL *)url{ 13 | self = [super initWithBaseURL:url]; 14 | if (!self) { 15 | return nil; 16 | } 17 | return self; 18 | } 19 | 20 | - (BOOL)isHttpQueueFinished:(NSArray *)httpUrlArray{ 21 | if(self.tasks.count == 0){ 22 | return YES; 23 | } 24 | 25 | //add filter urlString.length==0 26 | NSMutableArray* urlArray = [NSMutableArray array]; 27 | for (NSString* currentUrl in httpUrlArray) { 28 | if (currentUrl.length != 0) { 29 | [urlArray addObject:currentUrl]; 30 | } 31 | } 32 | 33 | //urlArray is empty 34 | if(urlArray.count == 0){ 35 | return YES; 36 | } 37 | 38 | for (NSURLSessionTask *task in self.tasks) { 39 | NSString *taskUrl = task.currentRequest.URL.absoluteString; 40 | for (NSString *baseUrl in urlArray) { 41 | if([taskUrl rangeOfString:baseUrl].location != NSNotFound){ 42 | return NO; 43 | } 44 | } 45 | } 46 | 47 | return YES; 48 | } 49 | 50 | - (void)cancelTasksWithUrl:(NSString *)url{ 51 | for (NSURLSessionTask *task in self.tasks) { 52 | NSString *taskUrl = task.currentRequest.URL.absoluteString; 53 | if([taskUrl rangeOfString:url].location != NSNotFound){ 54 | [task cancel]; 55 | } 56 | } 57 | } 58 | @end 59 | -------------------------------------------------------------------------------- /BGNetwork/BGAFRequestSerializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGAFRequestSerializer.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/20. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "AFURLRequestSerialization.h" 10 | @protocol BGAFRequestSerializerDelegate; 11 | 12 | @interface BGAFRequestSerializer : AFHTTPRequestSerializer 13 | @property (nonatomic, weak) _Nullable id delegate; 14 | @end 15 | 16 | @protocol BGAFRequestSerializerDelegate 17 | 18 | @required 19 | - ( NSURLRequest * _Nonnull )requestSerializer:( BGAFRequestSerializer * _Nonnull )requestSerializer request:( NSURLRequest * _Nonnull )request withParameters:(id _Nullable)parameters error:(NSError * _Nullable __autoreleasing * _Nullable)error; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /BGNetwork/BGAFRequestSerializer.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGAFRequestSerializer.m 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/20. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGAFRequestSerializer.h" 10 | 11 | @implementation BGAFRequestSerializer 12 | - (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request withParameters:(id)parameters error:(NSError *__autoreleasing *)error{ 13 | if(_delegate == nil){ 14 | return [super requestBySerializingRequest:request withParameters:parameters error:error]; 15 | } 16 | return [_delegate requestSerializer:self request:request withParameters:parameters error:error]; 17 | } 18 | @end 19 | -------------------------------------------------------------------------------- /BGNetwork/BGAFResponseSerializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGAFReponseSerializer.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/20. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "AFURLResponseSerialization.h" 10 | 11 | @interface BGAFResponseSerializer : AFHTTPResponseSerializer 12 | @end -------------------------------------------------------------------------------- /BGNetwork/BGAFResponseSerializer.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGAFReponseSerializer.m 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/20. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGAFResponseSerializer.h" 10 | 11 | @implementation BGAFResponseSerializer 12 | - (instancetype)init { 13 | self = [super init]; 14 | if (!self) { 15 | return nil; 16 | } 17 | 18 | self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",nil]; 19 | 20 | return self; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /BGNetwork/BGBatchRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGBatchRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/11/28. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BGNetworkRequest.h" 11 | 12 | /** 13 | * 批量发送请求 14 | */ 15 | @interface BGBatchRequest : NSObject 16 | /** 17 | * init method 18 | * @param requestArray 一组BGNetworkRequest 19 | */ 20 | - (instancetype _Nonnull)initWithRequests:(NSArray * _Nullable)requestArray; 21 | 22 | @property (nonatomic, readonly) NSArray * _Nonnull requestArray; 23 | 24 | /** 25 | * 当某个请求失败后,是否还继续加载其它请求,默认YES 26 | */ 27 | @property (nonatomic, assign) BOOL continueLoadWhenRequestFailure; 28 | 29 | /** 30 | * 设置每个请求失败回调 31 | * 32 | * @param businessFailureBlock BGNetworkRequest请求业务失败 33 | * @param networkFailureBlock BGNetworkRequest请求网络失败 34 | */ 35 | - (void)setBusinessFailure:(void (^ _Nullable)(BGNetworkRequest * _Nonnull request, id _Nullable response))businessFailureBlock 36 | networkFailure:(void (^ _Nullable)(BGNetworkRequest * _Nonnull request, NSError * _Nullable error))networkFailureBlock; 37 | 38 | /** 39 | * 批量发送请求 40 | * 41 | * @param successBlock 每个BGNetworkRequest请求成功回调 42 | * @param completionBlock 所有BGNetworkRequest请求完成后回调 43 | */ 44 | - (void)sendRequestSuccess:(void (^ _Nullable)(BGNetworkRequest * _Nonnull request, id _Nullable response))successBlock 45 | completion:(void (^ _Nullable)(BGBatchRequest * _Nonnull batchRequest, BOOL isAllSuccess))completionBlock; 46 | @end 47 | -------------------------------------------------------------------------------- /BGNetwork/BGBatchRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGBatchRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/11/28. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BGBatchRequest.h" 10 | 11 | @interface BGBatchRequest () 12 | @property (nonatomic, strong) NSArray *requestArray; 13 | @property (nonatomic, copy) void (^businessFailureBlock)(BGNetworkRequest *, id); 14 | @property (nonatomic, copy) void (^networkFailureBlock)(BGNetworkRequest *, NSError *); 15 | @end 16 | 17 | @implementation BGBatchRequest 18 | - (instancetype)init { 19 | return [self initWithRequests:nil]; 20 | } 21 | 22 | - (instancetype)initWithRequests:(NSArray *)requestArray { 23 | if(self = [super init]) { 24 | self.requestArray = requestArray; 25 | } 26 | return self; 27 | } 28 | 29 | - (void)clearRequestBlock { 30 | self.businessFailureBlock = nil; 31 | self.networkFailureBlock = nil; 32 | } 33 | 34 | - (void)setBusinessFailure:(void (^)(BGNetworkRequest *, id))businessFailureBlock networkFailure:(void (^)(BGNetworkRequest *, NSError *))networkFailureBlock { 35 | self.businessFailureBlock = businessFailureBlock; 36 | self.networkFailureBlock = networkFailureBlock; 37 | } 38 | 39 | - (void)sendRequestSuccess:(void (^)(BGNetworkRequest *, id))successBlock 40 | completion:(void (^)(BGBatchRequest *, BOOL))completionBlock { 41 | 42 | NSInteger requestCount = self.requestArray.count; 43 | __block NSInteger successCount = 0; 44 | 45 | for (BGNetworkRequest *request in self.requestArray) { 46 | [request sendRequestWithSuccess:^(BGNetworkRequest *request, id response) { 47 | successCount ++; 48 | if(successBlock) { 49 | successBlock(request, response); 50 | } 51 | if(successCount == requestCount) { 52 | [self clearRequestBlock]; 53 | if(completionBlock) { 54 | completionBlock(self, YES); 55 | } 56 | } 57 | } businessFailure:^(BGNetworkRequest *request, id response) { 58 | if(self.businessFailureBlock) { 59 | self.businessFailureBlock(request, response); 60 | } 61 | if(!self.continueLoadWhenRequestFailure) { 62 | [self clearRequestBlock]; 63 | [self cancelAllRequest]; 64 | if(completionBlock) { 65 | completionBlock(self, NO); 66 | } 67 | } 68 | } networkFailure:^(BGNetworkRequest *request, NSError *error) { 69 | if(self.networkFailureBlock) { 70 | self.networkFailureBlock(request, error); 71 | } 72 | if(!self.continueLoadWhenRequestFailure) { 73 | [self clearRequestBlock]; 74 | [self cancelAllRequest]; 75 | if(completionBlock) { 76 | completionBlock(self, NO); 77 | } 78 | } 79 | }]; 80 | } 81 | } 82 | 83 | - (void)cancelAllRequest { 84 | for (BGNetworkRequest *request in self.requestArray) { 85 | #warning 取消请求是否用类方法取消? 86 | [[request class] cancelRequest]; 87 | } 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /BGNetwork/BGDownloadRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGDownloadRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/21. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BGNetworkRequest.h" 11 | 12 | @interface BGDownloadRequest : NSObject 13 | /** 14 | * 请求标识码,每个请求都拥有唯一的标示 15 | */ 16 | @property (nonatomic, assign, readonly) NSUInteger requestIdentifier; 17 | 18 | /** 19 | * 方法名 20 | */ 21 | @property (nonatomic, strong) NSString * _Nonnull methodName; 22 | 23 | /** 24 | * 下载的文件名 25 | */ 26 | @property (nonatomic, strong) NSString * _Nonnull fileName; 27 | 28 | @end 29 | 30 | #pragma mark - BGNetworkRequest(BGNetworkManager) 31 | @interface BGDownloadRequest (BGNetworkManager) 32 | /** 33 | * 取消请求 34 | */ 35 | - (void)cancelRequest; 36 | 37 | - (void)sendRequestWithProgress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgressBlock 38 | success:(nullable void (^)(BGDownloadRequest * _Nonnull request, NSURL * _Nullable filePath))successCompletionBlock 39 | failure:(nullable void (^)(BGDownloadRequest * _Nonnull request, NSError * _Nullable error))failureCompletionBlock;; 40 | @end 41 | 42 | 43 | -------------------------------------------------------------------------------- /BGNetwork/BGDownloadRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGDownloadRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/21. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGDownloadRequest.h" 10 | #import "BGNetworkManager.h" 11 | 12 | static NSUInteger _requestIdentifier = 0; 13 | @implementation BGDownloadRequest 14 | 15 | - (instancetype)init{ 16 | if(self = [super init]){ 17 | _requestIdentifier += 1; 18 | } 19 | return self; 20 | } 21 | 22 | #pragma mark - set or get method 23 | - (NSUInteger)requestIdentifier { 24 | return _requestIdentifier; 25 | } 26 | 27 | - (NSDictionary *)parametersDic{ 28 | return [NSDictionary dictionary]; 29 | } 30 | 31 | - (NSDictionary *)requestHTTPHeaderFields { 32 | return [NSDictionary dictionary]; 33 | } 34 | 35 | @end 36 | 37 | @implementation BGDownloadRequest (BGNetworkManager) 38 | - (void)sendRequestWithProgress:(void (^)(NSProgress * _Nonnull))downloadProgressBlock 39 | success:(void (^)(BGDownloadRequest * _Nonnull, NSURL * _Nullable))successCompletionBlock 40 | failure:(void (^)(BGDownloadRequest * _Nonnull, NSError * _Nullable))failureCompletionBlock { 41 | [[BGNetworkManager sharedManager] sendDownloadRequest:self progress:downloadProgressBlock success:successCompletionBlock failure:failureCompletionBlock]; 42 | } 43 | 44 | /** 45 | * 取消请求 46 | */ 47 | - (void)cancelRequest { 48 | [[BGNetworkManager sharedManager] cancelDownloadRequest:self]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /BGNetwork/BGNetwork.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGNetwork.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/10. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #ifndef BGNetwork_h 10 | #define BGNetwork_h 11 | 12 | #import "BGNetworkManager.h" 13 | #import "BGAFRequestSerializer.h" 14 | #import "BGAFResponseSerializer.h" 15 | #import "BGBatchRequest.h" 16 | 17 | #endif /* BGNetwork_h */ 18 | -------------------------------------------------------------------------------- /BGNetwork/BGNetworkCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGNetworkCache.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/21. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BGNetworkCache : NSObject 12 | /** 13 | * 返回一个单例对象 14 | */ 15 | + (instancetype _Nonnull)sharedCache; 16 | 17 | /** 18 | * 初始化对象 19 | * 20 | * @param nameSpace 设置缓存空间 21 | * 22 | */ 23 | - (instancetype _Nonnull)initWithNamespace:(NSString * _Nonnull)nameSpace; 24 | 25 | /** 26 | * 默认缓存路径 27 | * 28 | * @param fileName 文件名 29 | * 30 | * @return 返回文件路径 31 | */ 32 | - (NSString * _Nonnull)defaultCachePathForFileName:(NSString * _Nonnull)fileName; 33 | 34 | #pragma mark - store 35 | /** 36 | * 缓存数据 37 | */ 38 | - (void)storeData:(NSData * _Nonnull)data forFileName:(NSString * _Nonnull)fileName; 39 | 40 | /** 41 | * 缓存数据 42 | */ 43 | - (void)storeData:(NSData * _Nonnull)data forFileName:(NSString * _Nonnull)fileName completion:(void (^ _Nullable)(BOOL isCacheSuccess))completionBlock; 44 | 45 | /** 46 | * 归档存储对象 47 | * 48 | * @param object 对象 49 | * @param key key值 50 | */ 51 | - (void)storeObject:(id _Nonnull)object forFileName:(NSString * _Nonnull)fileName completion:(void (^ _Nullable)(BOOL isCacheSuccess))completionBlock; 52 | 53 | /** 54 | * 归档存储对象 55 | * 56 | * @param object 对象 57 | * @param key key值 58 | */ 59 | - (void)storeObject:(id _Nonnull)object forFileName:(NSString * _Nonnull)fileName; 60 | 61 | 62 | #pragma mark - query 63 | /** 64 | * 查询缓存数据 65 | * @return 返回查询到的缓存数据 66 | */ 67 | - (NSData * _Nullable)queryDataCacheForFileName:(NSString * _Nonnull)fileName; 68 | 69 | /** 70 | * 查询缓存数据 71 | */ 72 | - (void)queryDataCacheForFileName:(NSString * _Nonnull)fileName completion:(void (^ _Nullable)(NSData* _Nullable data))completionBlock; 73 | 74 | /** 75 | * 查询缓存数据 76 | * @return 返回对象 77 | */ 78 | - (id _Nullable)queryObjectCacheForFileName:(NSString * _Nonnull)fileName; 79 | 80 | /** 81 | * 查询缓存数据 82 | * @return 返回的对象 83 | */ 84 | - (void)queryObjectCacheForFileName:(NSString * _Nonnull)fileName completion:(void (^ _Nullable)(id _Nullable object))completionBlock; 85 | 86 | 87 | #pragma mark - remove 88 | /** 89 | * 删除数据 90 | */ 91 | - (void)removeCacheForFileName:(NSString * _Nonnull)fileName; 92 | @end 93 | -------------------------------------------------------------------------------- /BGNetwork/BGNetworkConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGNetworkConfiguration.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/18. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BGNetworkRequest.h" 11 | 12 | @protocol BGNetworkConfiguration; 13 | 14 | @protocol BGNetworkConfiguration 15 | 16 | @required 17 | /** 18 | * 基础地址字符串 19 | */ 20 | @property (nonatomic, strong, readonly) NSString * _Nonnull baseURLString; 21 | 22 | 23 | @optional 24 | /** 25 | * 在请求以前,对request预处理一下,默认不处理 26 | * 27 | * @param request 请求 28 | * @note 此方法添加,为了适应多域名,可以对request.methodName设置一个绝对路径 29 | */ 30 | - (void)preProcessingRequest:(BGNetworkRequest * _Nonnull)request; 31 | 32 | /** 33 | * 对request当中的HTTP Header进行处理,可以在此方法内部加入公共的请求头内容 34 | * 35 | * @param request 请求 36 | * 37 | * @return 返回一个处理好的请求头给AF,默认加公共的Content-Type和User-Agent 38 | */ 39 | - (NSDictionary * _Nonnull)requestHTTPHeaderFields:(BGNetworkRequest * _Nonnull)request; 40 | 41 | /** 42 | * 组装url的query部分,其中默认GET请求会将参数全部用&连接,但POST请求返回nil 43 | * 44 | * @param request 请求,内部带有参数字典 45 | * 46 | * @return 返回一个字符串 47 | */ 48 | - (NSString * _Nullable)queryStringForURLWithRequest:(BGNetworkRequest * _Nonnull)request; 49 | 50 | /** 51 | * 组装http请求体,默认GET请求返回nil,POST请求返回一个json对象 52 | * 53 | * @param request 请求,内部带有参数字典 54 | * 55 | * @return 返回一个NSData数据类型 56 | * 57 | * @note 若是默认满足不了需求,请实现此方法;并且,若是需要加密,则可以在此请求当中处理 58 | */ 59 | - (NSData * _Nullable)httpBodyDataWithRequest:(BGNetworkRequest * _Nonnull)request; 60 | 61 | /** 62 | * 解密请求返回的数据,默认不解密,如果需要解密,实现此方法 63 | * 64 | * @param responseData 返回的数据 65 | * @param response response 66 | * @param request 请求 67 | * 68 | * @return 解密后的数据 69 | */ 70 | - (NSData * _Nullable)decryptResponseData:(NSData * _Nonnull)responseData response:(NSURLResponse * _Nonnull)response request:(BGNetworkRequest * _Nonnull)request; 71 | 72 | /** 73 | * 是否应该缓存当前的数据,里面根据request.cachePolicy来进行判断。若是根据服务器返回的一个字段来判断是否应该返回数据,子类覆写此方法 74 | * 75 | * @param responseData 请求到的数据,此数据已经经过json解析之后的数据 76 | * @param task task 77 | * @param request 请求 78 | * 79 | * @return 根据request.cachePolicy来判断 80 | * @code 81 | if(request.cachePolicy == BGNetworkRequestCacheDataAndReadCacheOnly || request.cachePolicy == BGNetworkRequestCacheDataAndReadCacheLoadData) { 82 | return YES; 83 | } 84 | return NO; 85 | */ 86 | - (BOOL)shouldCacheResponseData:(id _Nullable)responseData task:(NSURLSessionDataTask * _Nonnull)task request:(BGNetworkRequest * _Nonnull)request; 87 | 88 | /** 89 | * 是否业务成功,默认返回YES;子类若是需要判断走业务失败和业务成功流程,可以覆写此方法 90 | * 91 | * @param responseData 返回数据 92 | * @param task task 93 | * @param request 请求 94 | * 95 | * @return 默认返回YES,说明网络成功,则走成功流程; 96 | */ 97 | - (BOOL)shouldBusinessSuccessWithResponseData:(id _Nullable)responseData task:(NSURLSessionDataTask * _Nonnull)task request:(BGNetworkRequest * _Nonnull)request; 98 | 99 | @end 100 | 101 | /** 102 | * 网络配置,默认内部不进行加密解密,如果要加密解密,请子类化一个网络配置类,并且实现BGNetworkDataHandleProtocol协议 103 | */ 104 | @interface BGNetworkConfiguration : NSObject 105 | + (instancetype _Nonnull)configuration; 106 | + (instancetype _Nonnull)configurationWithBaseURL:(NSString * _Nonnull)baseURL; 107 | @end 108 | -------------------------------------------------------------------------------- /BGNetwork/BGNetworkConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGNetworkConfiguration.m 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/18. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGNetworkConfiguration.h" 10 | #import "BGUtilFunction.h" 11 | 12 | @interface BGNetworkConfiguration () 13 | @property(nonatomic, strong) NSString *baseURLString; 14 | @end 15 | 16 | @implementation BGNetworkConfiguration 17 | 18 | + (instancetype)configuration{ 19 | return [self configurationWithBaseURL: @""]; 20 | } 21 | 22 | + (instancetype _Nonnull)configurationWithBaseURL:(NSString *)baseURL { 23 | BGNetworkConfiguration *configuration = [[self alloc] init]; 24 | configuration.baseURLString = baseURL; 25 | return configuration; 26 | } 27 | 28 | #pragma mark - BGNetworkConfiguration 29 | - (NSString *)baseURLString { 30 | return _baseURLString; 31 | } 32 | 33 | - (void)preProcessingRequest:(BGNetworkRequest *)request { 34 | } 35 | 36 | - (NSDictionary *)requestHTTPHeaderFields:(BGNetworkRequest *)request { 37 | NSMutableDictionary *allHTTPHeaderFileds = [@{ 38 | @"Content-Type":@"application/x-www-form-urlencoded;charset=utf-8", 39 | @"User-Agent":@"iPhone" 40 | } mutableCopy]; 41 | [request.requestHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { 42 | allHTTPHeaderFileds[key] = obj; 43 | }]; 44 | return allHTTPHeaderFileds; 45 | } 46 | 47 | - (NSString *)queryStringForURLWithRequest:(BGNetworkRequest *)request{ 48 | if(request.httpMethod == BGNetworkRequestHTTPGet){ 49 | return BGQueryStringFromParamDictionary(request.parametersDic); 50 | } 51 | else{ 52 | return nil; 53 | } 54 | } 55 | 56 | - (NSData *)httpBodyDataWithRequest:(BGNetworkRequest *)request{ 57 | if(!request.parametersDic.count){ 58 | return nil; 59 | } 60 | NSError *error = nil; 61 | NSData *httpBody = [NSJSONSerialization dataWithJSONObject:request.parametersDic options: (NSJSONWritingOptions)0 error:&error]; 62 | if(error){ 63 | return nil; 64 | } 65 | return httpBody; 66 | } 67 | 68 | - (NSData *)decryptResponseData:(NSData *)responseData response:(NSURLResponse *)response request:(BGNetworkRequest *)request{ 69 | return responseData; 70 | } 71 | 72 | - (BOOL)shouldCacheResponseData:(id)responseData task:(NSURLSessionDataTask *)task request:(BGNetworkRequest *)request{ 73 | if(request.cachePolicy == BGNetworkRequestCacheDataAndReadCacheOnly || request.cachePolicy == BGNetworkRequestCacheDataAndReadCacheLoadData) { 74 | return YES; 75 | } 76 | return NO; 77 | } 78 | 79 | - (BOOL)shouldBusinessSuccessWithResponseData:(id)responseData task:(NSURLSessionDataTask *)task request:(BGNetworkRequest *)request { 80 | return YES; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /BGNetwork/BGNetworkManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGNetworkManager.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/14. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BGNetworkConfiguration.h" 11 | #import "BGNetworkRequest.h" 12 | #import "BGNetworkCache.h" 13 | #import "BGDownloadRequest.h" 14 | #import "BGUploadRequest.h" 15 | 16 | /** 17 | * 网络管理内,是一个单例,需要创建一个网络配置给此类使用 18 | */ 19 | @interface BGNetworkManager : NSObject 20 | + (instancetype _Nonnull)sharedManager; 21 | /** 22 | * 网络缓存 23 | */ 24 | @property (nonatomic, strong, readonly) BGNetworkCache * _Nonnull cache; 25 | 26 | /** 27 | * 设置网络配置 28 | */ 29 | @property (nonatomic, strong, readonly) BGNetworkConfiguration * _Nonnull configuration; 30 | 31 | /** 32 | * 设置网络配置 33 | * 34 | * @param configuration 网络配置 35 | */ 36 | - (void)setNetworkConfiguration:(BGNetworkConfiguration * _Nonnull)configuration; 37 | 38 | 39 | /** 40 | * 发送请求 41 | * 42 | * @param request 请求 43 | * @param successCompletionBlock 成功调回 44 | * @param businessFailureBlock 业务失败调回 45 | * @param networkFailureBlock 网络失败调回 46 | */ 47 | - (void)sendRequest:(BGNetworkRequest * _Nonnull)request 48 | success:(BGSuccessCompletionBlock _Nullable)successCompletionBlock 49 | businessFailure:(BGBusinessFailureBlock _Nullable)businessFailureBlock 50 | networkFailure:(BGNetworkFailureBlock _Nullable)networkFailureBlock; 51 | 52 | /** 53 | * 发送下载请求 54 | * 55 | * @param request 下载请求 56 | * @param downloadProgressBlock 下载的进度条 57 | * @param successCompletionBlock 下载成功 58 | * @param failureCompletionBlock 下载失败 59 | */ 60 | - (void)sendDownloadRequest:(BGDownloadRequest * _Nonnull)request 61 | progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgressBlock 62 | success:(nullable void (^)(BGDownloadRequest * _Nonnull request, NSURL * _Nullable filePath))successCompletionBlock 63 | failure:(nullable void (^)(BGDownloadRequest * _Nonnull request, NSError * _Nullable error))failureCompletionBlock; 64 | 65 | 66 | - (void)sendUploadRequest:(BGUploadRequest * _Nonnull)request 67 | progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress 68 | success:(BGSuccessCompletionBlock _Nullable)successCompletionBlock 69 | businessFailure:(BGBusinessFailureBlock _Nullable)businessFailureBlock 70 | networkFailure:(BGNetworkFailureBlock _Nullable)networkFailureBlock; 71 | 72 | /** 73 | * 取消请求 74 | * 75 | * @param url 取消请求的url 76 | */ 77 | - (void)cancelRequestWithUrl:(NSString * _Nonnull)url; 78 | 79 | /** 80 | * cancel download request 81 | */ 82 | - (void)cancelDownloadRequest:(BGDownloadRequest * _Nonnull)request; 83 | @end 84 | -------------------------------------------------------------------------------- /BGNetwork/BGNetworkRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGNetworkRequest.h 3 | // BGNetwork 4 | // 5 | // Created by user on 15/8/18. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class BGNetworkRequest; 12 | 13 | typedef NS_ENUM(NSInteger, BGNetworkRequestHTTPMethod){ 14 | /** 15 | * GET请求 16 | */ 17 | BGNetworkRequestHTTPGet, 18 | /** 19 | * POST请求 20 | */ 21 | BGNetworkRequestHTTPPost, 22 | }; 23 | 24 | /** 25 | * 网络请求缓存策略 26 | */ 27 | typedef NS_ENUM(NSInteger, BGNetworkRequestCachePolicy){ 28 | /** 29 | * 不进行缓存 30 | */ 31 | BGNetworkRquestCacheNone, 32 | /** 33 | * 请求到数据后缓存数据,读取缓存时如果有缓存则仅仅读取缓存,不再请求网络 34 | */ 35 | BGNetworkRequestCacheDataAndReadCacheOnly, 36 | /** 37 | * 请求到数据后缓存数据,读取到缓存后请求网络 38 | */ 39 | BGNetworkRequestCacheDataAndReadCacheLoadData, 40 | }; 41 | 42 | 43 | #pragma mark - completion block 44 | typedef void(^BGSuccessCompletionBlock)(BGNetworkRequest * _Nonnull request, id _Nullable response); 45 | typedef void(^BGBusinessFailureBlock)(BGNetworkRequest * _Nonnull request, id _Nullable response); 46 | typedef void(^BGNetworkFailureBlock)(BGNetworkRequest * _Nonnull request, NSError *_Nullable error); 47 | 48 | @protocol BGNetworkRequestDelegate; 49 | @protocol BGNetworkRequest 50 | /** 51 | * 处理请求到的数据,父类默认不处理直接返回,子类覆写此方法进行处理 52 | * 53 | * @param responseObject 请求到的数据 54 | * 55 | * @return 处理之后的数据 56 | */ 57 | - (id _Nullable)processResponseObject:(id _Nonnull)responseObject; 58 | 59 | @end 60 | 61 | #pragma mark - BGNetworkRequest 62 | /** 63 | * 请求类,覆写父类的方法请参照BGNetworkRequest协议进行覆写 64 | * @code 65 | * BGNetworkRequest *request = [[BGNetworkRequest alloc] init]; 66 | * [request sendRequestWithDelegate:self]; 67 | */ 68 | @interface BGNetworkRequest : NSObject 69 | 70 | /** 71 | * 请求标识码,每个请求都拥有唯一的标示 72 | */ 73 | @property (nonatomic, assign, readonly) NSUInteger requestIdentifier; 74 | /** 75 | * 方法名 76 | */ 77 | @property (nonatomic, strong) NSString * _Nonnull methodName; 78 | 79 | /** 80 | * HTTP请求的方法,默认GET,现支持GET和POST 81 | */ 82 | @property (nonatomic, assign) BGNetworkRequestHTTPMethod httpMethod; 83 | 84 | /** 85 | * 缓存策略,默认为BGNetworkRquestCacheNone 86 | */ 87 | @property (nonatomic, assign) BGNetworkRequestCachePolicy cachePolicy; 88 | 89 | /** 90 | * 参数字典 91 | */ 92 | @property (nonatomic, copy, readonly) NSDictionary * _Nonnull parametersDic; 93 | 94 | /** 95 | * 请求头 96 | */ 97 | @property (nonatomic, copy, readonly) NSDictionary * _Nonnull requestHTTPHeaderFields; 98 | 99 | 100 | #pragma mark - 设置或获取请求头的内容 101 | - (void)setValue:(NSString * _Nonnull)value forHTTPHeaderField:(NSString * _Nonnull)field; 102 | - (NSString * _Nonnull)valueForHTTPHeaderField:(NSString * _Nonnull)field; 103 | 104 | #pragma mark - 设置参数 105 | - (void)setIntegerValue:(NSInteger)value forParamKey:(NSString * _Nonnull)key; 106 | - (void)setDoubleValue:(double)value forParamKey:(NSString * _Nonnull)key; 107 | - (void)setLongLongValue:(long long)value forParamKey:(NSString * _Nonnull)key; 108 | - (void)setBOOLValue:(BOOL)value forParamKey:(NSString * _Nonnull)key; 109 | - (void)setValue:(id _Nonnull)value forParamKey:(NSString * _Nonnull)key; 110 | @end 111 | 112 | #pragma mark - BGNetworkRequest(BGNetworkManager) 113 | @interface BGNetworkRequest (BGNetworkManager) 114 | /** 115 | * 取消请求 116 | */ 117 | + (void)cancelRequest; 118 | 119 | /** 120 | * 发送网络请求 121 | * 122 | * @param successCompletionBlock 成功回调 123 | * @param businessFailureBlock 业务失败回调 124 | * @param networkFailureBlock 网络失败回调 125 | */ 126 | - (void)sendRequestWithSuccess:(BGSuccessCompletionBlock _Nullable)successCompletionBlock 127 | businessFailure:(BGBusinessFailureBlock _Nullable)businessFailureBlock 128 | networkFailure:(BGNetworkFailureBlock _Nullable)networkFailureBlock; 129 | @end 130 | -------------------------------------------------------------------------------- /BGNetwork/BGUploadRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGUploadRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/22. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGNetworkRequest.h" 10 | #import "AFNetworking.h" 11 | 12 | @interface BGUploadRequest : BGNetworkRequest 13 | /** 14 | * 初始化请求 15 | * 16 | * @param fileData 文件数据 17 | * 18 | * @return 返回请求对象 19 | */ 20 | - (instancetype _Nonnull)initWithData:(NSData * _Nonnull)fileData; 21 | 22 | /** 23 | * 文件数据 24 | */ 25 | @property (nonatomic, strong, readonly) NSData * _Nonnull fileData; 26 | 27 | /** 28 | * 上传数据的键值,默认为"fileUpload",不能为空 29 | */ 30 | @property (nonatomic, strong) NSString * _Nonnull uploadKey; 31 | 32 | /** 33 | * 文件名,默认为"upload" 34 | */ 35 | @property (nonatomic, strong) NSString * _Nonnull fileName; 36 | 37 | /** 38 | * 文件类型,默认为"application/octet-stream" 39 | */ 40 | @property (nonatomic, strong) NSString * _Nonnull mimeType; 41 | 42 | - (void)sendRequestWithProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress 43 | success:(BGSuccessCompletionBlock _Nullable)successCompletionBlock 44 | businessFailure:(BGBusinessFailureBlock _Nullable)businessFailureBlock 45 | networkFailure:(BGNetworkFailureBlock _Nullable)networkFailureBlock; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /BGNetwork/BGUploadRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGUploadRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/22. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGUploadRequest.h" 10 | #import "BGNetworkManager.h" 11 | 12 | @interface BGUploadRequest () 13 | @property (nonatomic, strong) NSData *fileData; 14 | @end 15 | @implementation BGUploadRequest 16 | 17 | - (instancetype)initWithData:(NSData *)fileData { 18 | if(self = [super init]) { 19 | self.fileData = fileData; 20 | self.uploadKey = @"fileUpload"; 21 | self.fileName = @"upload"; 22 | self.mimeType = @"application/octet-stream"; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)sendRequestWithSuccess:(BGSuccessCompletionBlock)successCompletionBlock businessFailure:(BGBusinessFailureBlock)businessFailureBlock networkFailure:(BGNetworkFailureBlock)networkFailureBlock { 28 | return [self sendRequestWithProgress:NULL success:successCompletionBlock businessFailure:businessFailureBlock networkFailure:networkFailureBlock]; 29 | } 30 | 31 | - (void)sendRequestWithProgress:(void (^)(NSProgress * _Nonnull))uploadProgress success:(BGSuccessCompletionBlock)successCompletionBlock businessFailure:(BGBusinessFailureBlock)businessFailureBlock networkFailure:(BGNetworkFailureBlock)networkFailureBlock { 32 | [[BGNetworkManager sharedManager] sendUploadRequest:self progress:uploadProgress success:successCompletionBlock businessFailure:businessFailureBlock networkFailure:networkFailureBlock]; 33 | } 34 | @end 35 | -------------------------------------------------------------------------------- /BGNetwork/BGUtilFunction.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGUtilFunction.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/24. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * 生成MD5 13 | */ 14 | FOUNDATION_EXPORT NSString * const _Nonnull BG_MD5(NSString * _Nonnull value); 15 | 16 | /** 17 | * 生成queryString 18 | */ 19 | FOUNDATION_EXPORT NSString * const _Nonnull BGQueryStringFromParamDictionary(NSDictionary * _Nonnull paramDic); 20 | 21 | /** 22 | * 由参数、方法名、URL生成一个唯一的key 23 | */ 24 | FOUNDATION_EXPORT NSString * const _Nonnull BGKeyFromParamsAndURLString(NSDictionary * _Nullable paramDic, NSString * _Nonnull URLString); 25 | -------------------------------------------------------------------------------- /BGNetwork/BGUtilFunction.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGUtilFunction.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/24. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGUtilFunction.h" 10 | #import 11 | 12 | NSString * const BG_MD5(NSString *value) { 13 | const char *str = [value UTF8String]; 14 | if (str == NULL) { 15 | str = ""; 16 | } 17 | unsigned char r[CC_MD5_DIGEST_LENGTH]; 18 | CC_MD5(str, (CC_LONG)strlen(str), r); 19 | NSString *md5Str = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 20 | r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]]; 21 | 22 | return md5Str; 23 | } 24 | 25 | NSArray *BGQueryStringFromKeyAndValue(NSString *key, id value){ 26 | NSMutableArray *array = [NSMutableArray array]; 27 | if([value isKindOfClass:[NSDictionary class]]){ 28 | [(NSDictionary *)value enumerateKeysAndObjectsUsingBlock:^(NSString *dicKey, id obj, BOOL *stop) { 29 | NSString *resultKey = [NSString stringWithFormat:@"%@[%@]", key, dicKey]; 30 | [array addObjectsFromArray:BGQueryStringFromKeyAndValue(resultKey, obj)]; 31 | }]; 32 | } 33 | else if([value isKindOfClass:[NSArray class]]){ 34 | [(NSArray *)value enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 35 | NSString *resultKey = [NSString stringWithFormat:@"%@[]", key]; 36 | [array addObjectsFromArray:BGQueryStringFromKeyAndValue(resultKey, obj)]; 37 | }]; 38 | } 39 | else if([value isKindOfClass:[NSSet class]]){ 40 | [(NSSet *)value enumerateObjectsUsingBlock:^(id obj, BOOL *stop) { 41 | NSString *resultKey = [NSString stringWithFormat:@"%@[]", key]; 42 | [array addObjectsFromArray:BGQueryStringFromKeyAndValue(resultKey, obj)]; 43 | }]; 44 | } 45 | else{ 46 | [array addObject:[NSString stringWithFormat:@"%@=%@", key, value]]; 47 | } 48 | return array; 49 | } 50 | 51 | NSString * const BGQueryStringFromParamDictionary(NSDictionary *paramDic){ 52 | NSMutableArray *array = [NSMutableArray array]; 53 | [paramDic enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { 54 | [array addObjectsFromArray:BGQueryStringFromKeyAndValue(key, obj)]; 55 | }]; 56 | return [array componentsJoinedByString:@"&"]; 57 | } 58 | 59 | NSString * const BGKeyFromParamsAndURLString(NSDictionary *paramDic, NSString * URLString){ 60 | 61 | //先进行排序 62 | NSArray *keys = [paramDic allKeys]; 63 | NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 64 | return [obj1 compare:obj2 options:NSNumericSearch]; 65 | }]; 66 | 67 | //组装字符串 68 | NSMutableString *keyMutableString = [NSMutableString string]; 69 | for (NSInteger index = 0; index < sortedArray.count; index++) { 70 | NSString *key = [sortedArray objectAtIndex:index]; 71 | NSString *value = [paramDic objectForKey:key]; 72 | if (index == 0) { 73 | [keyMutableString appendFormat:@"%@=%@",key,value]; 74 | } else { 75 | [keyMutableString appendFormat:@"|%@=%@",key,value]; 76 | } 77 | } 78 | [keyMutableString appendString:URLString]; 79 | 80 | return BG_MD5(keyMutableString); 81 | } -------------------------------------------------------------------------------- /BGNetworkDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BGNetworkDemo.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 68 | 69 | 70 | 72 | 84 | 85 | 86 | 88 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /BGNetworkDemo.xcodeproj/xcuserdata/user.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | BGNetworkDemo.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | CEF8E4121B99464C0087CDB3 16 | 17 | primary 18 | 19 | 20 | CEF8E42B1B99464C0087CDB3 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /BGNetworkDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /BGNetworkDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "DemoNetworkConfiguration.h" 11 | #import "BGNetwork.h" 12 | 13 | @interface AppDelegate () 14 | 15 | @end 16 | 17 | @implementation AppDelegate 18 | 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 21 | //对网络进行配置 22 | [[BGNetworkManager sharedManager] setNetworkConfiguration:[DemoNetworkConfiguration configuration]]; 23 | // Override point for customization after application launch. 24 | return YES; 25 | } 26 | 27 | - (void)applicationWillResignActive:(UIApplication *)application { 28 | // 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. 29 | // 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. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application { 33 | // 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. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /BGNetworkDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /BGNetworkDemo/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" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /BGNetworkDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | lcg.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | NSAppTransportSecurity 40 | 41 | NSAllowsArbitraryLoads 42 | 43 | NSExceptionDomains 44 | 45 | 172.16.4.115 46 | 47 | NSExceptionRequiresForwardSecrecy 48 | 49 | NSExceptionMinimumTLSVersion 50 | TLSv1.0 51 | NSExceptionAllowsInsecureHTTPLoads 52 | YES 53 | 54 | 192.168.31.186 55 | 56 | NSExceptionRequiresForwardSecrecy 57 | 58 | NSExceptionMinimumTLSVersion 59 | TLSv1.0 60 | NSExceptionAllowsInsecureHTTPLoads 61 | YES 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/Console/M13ProgressConsole.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressConsole.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import 15 | #import "M13ProgressView.h" 16 | 17 | typedef enum { 18 | M13ProgressConsoleMaskTypeNone, 19 | M13ProgressConsoleMaskTypeSolidColor, 20 | M13ProgressConsoleMaskTypeIOS7Blur 21 | } M13ProgressConsoleMaskType; 22 | 23 | typedef enum { 24 | M13ProgressConsoleProgressTypePercentage, 25 | M13ProgressConsoleProgressTypeDots, 26 | M13ProgressConsoleProgressTypeBarOfDots 27 | } M13ProgressConsoleProgressType; 28 | 29 | /**A progress view that shows progress in the style of terminal.*/ 30 | @interface M13ProgressConsole : UITextView; 31 | 32 | /**@name Progress*/ 33 | /**The progress displayed to the user.*/ 34 | @property (nonatomic, readonly) CGFloat progress; 35 | /**Wether or not the progress view is indeterminate.*/ 36 | @property (nonatomic, assign) BOOL indeterminate; 37 | /**Show progress at the end of each line.*/ 38 | @property (nonatomic, assign) M13ProgressConsoleProgressType progressType; 39 | 40 | /**@name Appearance*/ 41 | /**The background type of the console.*/ 42 | @property (nonatomic, assign) M13ProgressConsoleMaskType maskType; 43 | /**The color of the mask if set to solid color.*/ 44 | @property (nonatomic, retain) UIColor *maskColor; 45 | /**Wether or not to show the cursor.*/ 46 | @property (nonatomic, assign) BOOL showCursor; 47 | /**The prefix string for each line.*/ 48 | @property (nonatomic, retain) NSString *prefix; 49 | /**The array containing all the lines displyed.*/ 50 | @property (nonatomic, retain) NSArray *lines; 51 | 52 | /**@name Properties*/ 53 | /**The durations of animations in seconds.*/ 54 | @property (nonatomic, assign) CGFloat animationDuration; 55 | 56 | /**@name Actions*/ 57 | /**Set the progress of the `M13ProgressView`. 58 | @param progress The progress to show on the current line.*/ 59 | - (void)setProgress:(CGFloat)progress; 60 | /**Set the text of the current line. 61 | @param currentLine The string to replace the current line with.*/ 62 | - (void)setCurrentLine:(NSString *)currentLine; 63 | /**Add a new line with the given text. 64 | @param newLine The text to start a new line with.*/ 65 | - (void)addNewLineWithString:(NSString *)newLine; 66 | /**Clears the console.*/ 67 | - (void)clear; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/NavigationController/UINavigationController+M13ProgressViewBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationController+M13ProgressViewBar.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import 15 | 16 | /**A UINavagationController category that adds a progress view to the UINavigationBar.*/ 17 | @interface UINavigationController (M13ProgressViewBar) 18 | 19 | /**@name Actions*/ 20 | 21 | /**Show the progress bar.*/ 22 | - (void)showProgress; 23 | /**Set the progress to display on the progress bar. 24 | @param progress The progress to display as a percentage from 0-1. 25 | @param animated Wether or not to animate the change.*/ 26 | - (void)setProgress:(CGFloat)progress animated:(BOOL)animated; 27 | /**Set the string to replace the UINavigationBar's title with while showing progress. Send nil to reset the title. 28 | @param title The string to replace the UINavigationBar's title while showing progress.*/ 29 | - (void)setProgressTitle:(NSString *)title; 30 | /**Set whether or not to show indeterminate. 31 | @param indeterminate wether or not the progress bar is indeterminate.*/ 32 | - (void)setIndeterminate:(BOOL)indeterminate; 33 | /**Get whether or not to show indeterminate.*/ 34 | - (BOOL)getIndeterminate; 35 | /**Fill the progress bar completely and remove it from display.*/ 36 | - (void)finishProgress; 37 | /**Remove the progress bar from the display.*/ 38 | - (void)cancelProgress; 39 | /**Wether or not the progress bar is showing.*/ 40 | - (BOOL)isShowingProgressBar; 41 | /** 42 | The primary color of the progress bar if you do not want it to be the same as the UINavigationBar's tint color. If set to nil, the UINavigationBar's tint color will be used. 43 | 44 | @param primaryColor The color to set. 45 | */ 46 | - (void)setPrimaryColor:(UIColor *)primaryColor; 47 | /** 48 | The secondary color of the progress bar, if nil, the secondary color will be the barTintColor. 49 | 50 | @param secondaryColor The color to set. 51 | */ 52 | - (void)setSecondaryColor:(UIColor *)secondaryColor; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressView.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import 15 | 16 | typedef enum { 17 | /**Resets the action and returns the progress view to its normal state.*/ 18 | M13ProgressViewActionNone, 19 | /**The progress view shows success.*/ 20 | M13ProgressViewActionSuccess, 21 | /**The progress view shows failure.*/ 22 | M13ProgressViewActionFailure 23 | } M13ProgressViewAction; 24 | 25 | /**A standardized base upon which to build progress views for applications. This allows one to use any subclass progress view in any component that use this standard.*/ 26 | @interface M13ProgressView : UIView 27 | 28 | /**@name Appearance*/ 29 | /**The primary color of the `M13ProgressView`.*/ 30 | @property (nonatomic, retain) UIColor *primaryColor; 31 | /**The secondary color of the `M13ProgressView`.*/ 32 | @property (nonatomic, retain) UIColor *secondaryColor; 33 | 34 | /**@name Properties*/ 35 | /**Wether or not the progress view is indeterminate.*/ 36 | @property (nonatomic, assign) BOOL indeterminate; 37 | /**The durations of animations in seconds.*/ 38 | @property (nonatomic, assign) CGFloat animationDuration; 39 | /**The progress displayed to the user.*/ 40 | @property (nonatomic, readonly) CGFloat progress; 41 | 42 | /**@name Actions*/ 43 | /**Set the progress of the `M13ProgressView`. 44 | @param progress The progress to show on the progress view. 45 | @param animated Wether or not to animate the progress change.*/ 46 | - (void)setProgress:(CGFloat)progress animated:(BOOL)animated; 47 | /**Perform the given action if defined. Usually showing success or failure. 48 | @param action The action to perform. 49 | @param animated Wether or not to animate the change*/ 50 | - (void)performAction:(M13ProgressViewAction)action animated:(BOOL)animated; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressView.m 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | @implementation M13ProgressView 17 | 18 | - (id)initWithFrame:(CGRect)frame 19 | { 20 | self = [super initWithFrame:frame]; 21 | if (self) { 22 | // Initialization code 23 | } 24 | return self; 25 | } 26 | 27 | - (void)setProgress:(CGFloat)progress animated:(BOOL)animated 28 | { 29 | _progress = progress; 30 | } 31 | 32 | - (void)performAction:(M13ProgressViewAction)action animated:(BOOL)animated 33 | { 34 | //To be overriden in subclasses 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewBar.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | typedef enum { 17 | M13ProgressViewBarPercentagePositionLeft, 18 | M13ProgressViewBarPercentagePositionRight, 19 | M13ProgressViewBarPercentagePositionTop, 20 | M13ProgressViewBarPercentagePositionBottom, 21 | } M13ProgressViewBarPercentagePosition; 22 | 23 | typedef enum { 24 | M13ProgressViewBarProgressDirectionLeftToRight, 25 | M13ProgressViewBarProgressDirectionBottomToTop, 26 | M13ProgressViewBarProgressDirectionRightToLeft, 27 | M13ProgressViewBarProgressDirectionTopToBottom 28 | } M13ProgressViewBarProgressDirection; 29 | 30 | /**A replacement for UIProgressBar.*/ 31 | @interface M13ProgressViewBar : M13ProgressView 32 | 33 | /**@name Appearance*/ 34 | /**The direction of progress. (What direction the fill proceeds in.)*/ 35 | @property (nonatomic, assign) M13ProgressViewBarProgressDirection progressDirection; 36 | /**The thickness of the progress bar.*/ 37 | @property (nonatomic, assign) CGFloat progressBarThickness; 38 | /**The corner radius of the progress bar.*/ 39 | @property (nonatomic, assign) CGFloat progressBarCornerRadius; 40 | /**@name Actions*/ 41 | /**The color the bar changes to for the success action.*/ 42 | @property (nonatomic, retain) UIColor *successColor; 43 | /**The color the bar changes to for the failure action.*/ 44 | @property (nonatomic, retain) UIColor *failureColor; 45 | /**@name Percentage*/ 46 | /**Wether or not to show percentage text. If shown exterior to the progress bar, the progress bar is shifted to make room for the text.*/ 47 | @property (nonatomic, assign) BOOL showPercentage; 48 | /**The location of the percentage in comparison to the progress bar.*/ 49 | @property (nonatomic, assign) M13ProgressViewBarPercentagePosition percentagePosition; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewBorderedBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewBorderedBar.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | typedef enum { 17 | M13ProgressViewBorderedBarProgressDirectionLeftToRight, 18 | M13ProgressViewBorderedBarProgressDirectionBottomToTop, 19 | M13ProgressViewBorderedBarProgressDirectionRightToLeft, 20 | M13ProgressViewBorderedBarProgressDirectionTopToBottom 21 | } M13ProgressViewBorderedBarProgressDirection; 22 | 23 | typedef enum { 24 | M13ProgressViewBorderedBarCornerTypeSquare, 25 | M13ProgressViewBorderedBarCornerTypeRounded, 26 | M13ProgressViewBorderedBarCornerTypeCircle 27 | } M13ProgressViewBorderedBarCornerType; 28 | 29 | /**A Progress bar with a thick border.*/ 30 | @interface M13ProgressViewBorderedBar : M13ProgressView 31 | 32 | /**@name Appearance*/ 33 | /**The direction of progress. (What direction the fill proceeds in.)*/ 34 | @property (nonatomic, assign) M13ProgressViewBorderedBarProgressDirection progressDirection; 35 | /**The type of corner to display on the bar.*/ 36 | @property (nonatomic, assign) M13ProgressViewBorderedBarCornerType cornerType; 37 | /**The corner radius of the ber if the corner type is set to Rounded.*/ 38 | @property (nonatomic, assign) CGFloat cornerRadius; 39 | /**The border width of the progress bar.*/ 40 | @property (nonatomic, assign) CGFloat borderWidth; 41 | /**@name Actions*/ 42 | /**The color the bar changes to for the success action.*/ 43 | @property (nonatomic, retain) UIColor *successColor; 44 | /**The color the bar changes to for the failure action.*/ 45 | @property (nonatomic, retain) UIColor *failureColor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewFilteredImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewFilteredImage.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | #import 16 | 17 | #define kM13ProgressViewFilteredImageCIFilterStartValuesKey @"StartValues" 18 | #define kM13ProgressViewFilteredImageCIFilterEndValuesKey @"EndValues" 19 | 20 | /**A progress view where progress is shown by changes in CIFilters. 21 | @note This progress bar does not have in indeterminate mode and does not respond to actions.*/ 22 | @interface M13ProgressViewFilteredImage : M13ProgressView 23 | 24 | /**@name Appearance*/ 25 | /**The image to use when showing progress.*/ 26 | @property (nonatomic, retain) UIImage *progressImage; 27 | /**The UIImageView that shows the progress image.*/ 28 | @property (nonatomic, retain) UIImageView *progressView; 29 | /**The array of CIFilters to apply to the image. 30 | @note The filters need to be encased in a M13ProgressViewCIFilterWrapper*/ 31 | @property (nonatomic, retain) NSArray *filters; 32 | /**The dictionaries of dictionaries that coresspond to filter properties to be changed. 33 | NSArray 34 | |------ NSDictionary (Index matches the coresponding CIFilter in filters) 35 | | |---- "Parameter Key" -> NSDictionary 36 | | | |------ "Start Value" -> NSNumber 37 | | | |------ "End Value" -> NSNumber 38 | | |---- "Parameter Key" -> NSDictionary 39 | | |------ "Start Value" -> NSNumber 40 | | |------ "End Value" -> NSNumber 41 | |------ NSDictionary ... */ 42 | @property (nonatomic, retain) NSArray *filterParameters; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewImage.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | typedef enum { 17 | M13ProgressViewImageProgressDirectionLeftToRight, 18 | M13ProgressViewImageProgressDirectionBottomToTop, 19 | M13ProgressViewImageProgressDirectionRightToLeft, 20 | M13ProgressViewImageProgressDirectionTopToBottom 21 | } M13ProgressViewImageProgressDirection; 22 | 23 | /**A progress bar where progress is shown by cutting an image. 24 | @note This progress bar does not have in indeterminate mode and does not respond to actions.*/ 25 | @interface M13ProgressViewImage : M13ProgressView 26 | 27 | /**@name Appearance*/ 28 | /**The image to use when showing progress.*/ 29 | @property (nonatomic, retain) UIImage *progressImage; 30 | /**The direction of progress. (What direction the fill proceeds in.)*/ 31 | @property (nonatomic, assign) M13ProgressViewImageProgressDirection progressDirection; 32 | /**Wether or not to draw the greyscale background.*/ 33 | @property (nonatomic, assign) BOOL drawGreyscaleBackground; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewLetterpress.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewLetterpress.h 3 | // M13ProgressSuite 4 | // 5 | // Created by Brandon McQuilkin on 4/28/14. 6 | // Copyright (c) 2014 Brandon McQuilkin. All rights reserved. 7 | // 8 | 9 | #import "M13ProgressView.h" 10 | 11 | typedef enum { 12 | M13ProgressViewLetterpressPointShapeSquare, 13 | M13ProgressViewLetterpressPointShapeCircle 14 | } M13ProgressViewLetterpressPointShape; 15 | 16 | @interface M13ProgressViewLetterpress : M13ProgressView 17 | /**@name Properties*/ 18 | /** 19 | The number of grid points in each direction. 20 | */ 21 | @property (nonatomic, assign) CGPoint numberOfGridPoints; 22 | /** 23 | The shape of the grid points. 24 | */ 25 | @property (nonatomic, assign) M13ProgressViewLetterpressPointShape pointShape; 26 | /** 27 | The amount of space between the grid points, as a percentage of the point's size. 28 | */ 29 | @property (nonatomic, assign) CGFloat pointSpacing; 30 | /** 31 | The size of the notch to carve out on one side. 32 | */ 33 | @property (nonatomic, assign) CGSize notchSize; 34 | /** 35 | The spring constant that defines the amount of "spring" the progress view has in its animation. 36 | */ 37 | @property (nonatomic, assign) CGFloat springConstant; 38 | /** 39 | The constant that determines how long the progress view "bounces" for. 40 | */ 41 | @property (nonatomic, assign) CGFloat dampingCoefficient; 42 | /** 43 | The constant that determines how much the springConstant and dampingCoefficent affect the animation. 44 | */ 45 | @property (nonatomic, assign) CGFloat mass; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewMetro.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewMetro.h 3 | // M13ProgressSuite 4 | // 5 | // Created by Brandon McQuilkin on 3/8/14. 6 | // Copyright (c) 2014 Brandon McQuilkin. All rights reserved. 7 | // 8 | 9 | #import "M13ProgressView.h" 10 | 11 | typedef enum { 12 | M13ProgressViewMetroAnimationShapeEllipse, 13 | M13ProgressViewMetroAnimationShapeRectangle, 14 | M13ProgressViewMetroAnimationShapeLine 15 | } M13ProgressViewMetroAnimationShape; 16 | 17 | /**The layer that the `M13ProgressViewMetro` animates.*/ 18 | @interface M13ProgressViewMetroDot : CALayer 19 | 20 | /**Wether or not the dot is highlighted. The dot becomes highlighted to show progress.*/ 21 | @property (nonatomic, assign) BOOL highlighted; 22 | /**The color to show on success.*/ 23 | @property (nonatomic, retain) UIColor *successColor; 24 | /**The color to show on failure.*/ 25 | @property (nonatomic, retain) UIColor *failureColor; 26 | /**The primary color of the dot.*/ 27 | @property (nonatomic, retain) UIColor *primaryColor; 28 | /**The secondary color of the dot.*/ 29 | @property (nonatomic, retain) UIColor *secondaryColor; 30 | /**Perform the given action if defined. Usually showing success or failure. 31 | @param action The action to perform. 32 | @param animated Wether or not to animate the change*/ 33 | - (void)performAction:(M13ProgressViewAction)action animated:(BOOL)animated; 34 | 35 | @end 36 | 37 | /**A progress view based off of Windows 8's progress animation.*/ 38 | @interface M13ProgressViewMetro : M13ProgressView 39 | 40 | /**@name Properties*/ 41 | /**The number of dots in the animation.*/ 42 | @property (nonatomic, assign) NSUInteger numberOfDots; 43 | /**The shape of the animation.*/ 44 | @property (nonatomic, assign) M13ProgressViewMetroAnimationShape animationShape; 45 | /**The size of the dots*/ 46 | @property (nonatomic, assign) CGSize dotSize; 47 | /**The dot to display.*/ 48 | @property (nonatomic, retain) M13ProgressViewMetroDot *metroDot; 49 | /**@name Appearance*/ 50 | /**The color to show on success.*/ 51 | @property (nonatomic, retain) UIColor *successColor; 52 | /**The color to show on failure.*/ 53 | @property (nonatomic, retain) UIColor *failureColor; 54 | /**@name Actions*/ 55 | /**Wether or not the progress view animating.*/ 56 | - (BOOL)isAnimating; 57 | /**Begin the animation.*/ 58 | - (void)beginAnimating; 59 | /**End the animation.*/ 60 | - (void)stopAnimating; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewMetroDotPolygon.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewMetroDotShape.h 3 | // M13ProgressSuite 4 | // 5 | // Created by Brandon McQuilkin on 3/9/14. 6 | // Copyright (c) 2014 Brandon McQuilkin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "M13ProgressViewMetro.h" 11 | 12 | /**A subclass of M13ProgressViewMetroDot.*/ 13 | @interface M13ProgressViewMetroDotPolygon : M13ProgressViewMetroDot 14 | 15 | /**The number of sides the polygon has. 16 | @note if set less than 3, the polygon will be a circle.*/ 17 | @property (nonatomic, assign) NSUInteger numberOfSides; 18 | /**The radius of the polygon.*/ 19 | @property (nonatomic, assign) CGFloat radius; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewMetroDotPolygon.m: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewMetroDotShape.m 3 | // M13ProgressSuite 4 | // 5 | // Created by Brandon McQuilkin on 3/9/14. 6 | // Copyright (c) 2014 Brandon McQuilkin. All rights reserved. 7 | // 8 | 9 | #import "M13ProgressViewMetroDotPolygon.h" 10 | 11 | @implementation M13ProgressViewMetroDotPolygon 12 | { 13 | CAShapeLayer *shapeLayer; 14 | M13ProgressViewAction currentAction; 15 | } 16 | 17 | - (void)setNumberOfSides:(NSUInteger)numberOfSides 18 | { 19 | _numberOfSides = numberOfSides; 20 | [self setNeedsDisplay]; 21 | } 22 | 23 | - (void)setRadius:(CGFloat)radius 24 | { 25 | _radius = radius; 26 | [self setNeedsDisplay]; 27 | } 28 | 29 | - (NSArray *)verticies 30 | { 31 | if (_numberOfSides < 3) { 32 | return nil; 33 | } else { 34 | NSMutableArray *pointsArray = [NSMutableArray array]; 35 | for (int i = 0; i < _numberOfSides; i++) { 36 | CGPoint point = CGPointMake(_radius * cosf((2.0 * M_PI * (float)i) / (float)_numberOfSides), _radius * sinf((2.0 * M_PI * (float)i) / (float)_numberOfSides)); 37 | NSValue *value = [NSValue valueWithCGPoint:point]; 38 | [pointsArray addObject:value]; 39 | } 40 | return pointsArray; 41 | } 42 | } 43 | 44 | - (void)drawInContext:(CGContextRef)ctx 45 | { 46 | //Create and add the polygon layer if it does not exist 47 | if (shapeLayer == nil) { 48 | shapeLayer = [CAShapeLayer layer]; 49 | [self addSublayer:shapeLayer]; 50 | } 51 | //Create the path for the polygon 52 | UIBezierPath *path = [UIBezierPath bezierPath]; 53 | NSArray *verticies = [self verticies]; 54 | if (verticies == nil) { 55 | //Draw circle 56 | path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, _radius * 2, _radius * 2)]; 57 | } else { 58 | [path moveToPoint:((NSValue *)verticies[0]).CGPointValue]; 59 | for (int i = 1; i < verticies.count; i++) { 60 | [path addLineToPoint:((NSValue *)verticies[i]).CGPointValue]; 61 | } 62 | [path closePath]; 63 | } 64 | //Set the shape layer's path 65 | shapeLayer.path = path.CGPath; 66 | 67 | //Set the color of the polygon 68 | shapeLayer.fillColor = self.secondaryColor.CGColor; 69 | if (self.highlighted) { 70 | shapeLayer.fillColor = self.primaryColor.CGColor; 71 | } 72 | if (currentAction == M13ProgressViewActionSuccess) { 73 | shapeLayer.fillColor = self.successColor.CGColor; 74 | } else if (currentAction == M13ProgressViewActionFailure) { 75 | shapeLayer.fillColor = self.failureColor.CGColor; 76 | } 77 | 78 | //Draw 79 | [super drawInContext:ctx]; 80 | } 81 | 82 | - (void)performAction:(M13ProgressViewAction)action animated:(BOOL)animated 83 | { 84 | currentAction = action; 85 | [self setNeedsDisplay]; 86 | } 87 | 88 | - (id)copy 89 | { 90 | M13ProgressViewMetroDotPolygon *dot = [[M13ProgressViewMetroDotPolygon alloc] init]; 91 | dot.primaryColor = self.primaryColor; 92 | dot.secondaryColor = self.secondaryColor; 93 | dot.successColor = self.successColor; 94 | dot.failureColor = self.failureColor; 95 | dot.numberOfSides = _numberOfSides; 96 | dot.radius = _radius; 97 | return dot; 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewPie.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewPie.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | /**A progress view that shows progress with a pie chart.*/ 17 | @interface M13ProgressViewPie : M13ProgressView 18 | 19 | /**@name Appearance*/ 20 | /**The thickness of the border around the pie.*/ 21 | @property (nonatomic, assign) CGFloat backgroundRingWidth; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewRadiative.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewRadiative.h 3 | // M13ProgressSuite 4 | // 5 | // Created by Brandon McQuilkin on 3/13/14. 6 | // Copyright (c) 2014 Brandon McQuilkin. All rights reserved. 7 | // 8 | 9 | #import "M13ProgressView.h" 10 | 11 | typedef enum { 12 | M13ProgressViewRadiativeShapeCircle, 13 | M13ProgressViewRadiativeShapeSquare 14 | } M13ProgressViewRadiativeShape; 15 | 16 | /**A progress view that displays progress via "Radiative" rings around a central point.*/ 17 | @interface M13ProgressViewRadiative : M13ProgressView 18 | 19 | /**@name Appearance*/ 20 | /**The point where the wave fronts originate from. The point is defined in percentages, top left being {0, 0}, and the bottom right being {1, 1}.*/ 21 | @property (nonatomic, assign) CGPoint originationPoint; 22 | /**The distance of the last ripple from the origination point.*/ 23 | @property (nonatomic, assign) CGFloat ripplesRadius; 24 | /**The width of the ripples.*/ 25 | @property (nonatomic, assign) CGFloat rippleWidth; 26 | /**The shape of the radiative ripples*/ 27 | @property (nonatomic, assign) M13ProgressViewRadiativeShape shape; 28 | /**The number of ripples the progress view displays.*/ 29 | @property (nonatomic, assign) NSUInteger numberOfRipples; 30 | /**The number of ripples the indeterminate pulse animation is.*/ 31 | @property (nonatomic, assign) NSUInteger pulseWidth; 32 | /**The direction of the progress. If set to yes, the progress will be outward, of set to no, it will be inwards.*/ 33 | @property (nonatomic, assign) BOOL progressOutwards; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewRing.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewRing.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | /**A progress view stylized similarly to the iOS 7 App store progress view.*/ 17 | @interface M13ProgressViewRing : M13ProgressView 18 | 19 | /**@name Appearance*/ 20 | /**The width of the background ring in points.*/ 21 | @property (nonatomic, assign) CGFloat backgroundRingWidth; 22 | /**The width of the progress ring in points.*/ 23 | @property (nonatomic, assign) CGFloat progressRingWidth; 24 | /**@name Percentage*/ 25 | /**Wether or not to display a percentage inside the ring.*/ 26 | @property (nonatomic, assign) BOOL showPercentage; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewSegmentedBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewSegmentedBar.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | typedef enum { 17 | M13ProgressViewSegmentedBarProgressDirectionLeftToRight, 18 | M13ProgressViewSegmentedBarProgressDirectionBottomToTop, 19 | M13ProgressViewSegmentedBarProgressDirectionRightToLeft, 20 | M13ProgressViewSegmentedBarProgressDirectionTopToBottom 21 | } M13ProgressViewSegmentedBarProgressDirection; 22 | 23 | typedef enum { 24 | M13ProgressViewSegmentedBarSegmentShapeRectangle, 25 | M13ProgressViewSegmentedBarSegmentShapeRoundedRect, 26 | M13ProgressViewSegmentedBarSegmentShapeCircle 27 | } M13ProgressViewSegmentedBarSegmentShape; 28 | 29 | /**A progress bar that shows progress with discrete values.*/ 30 | @interface M13ProgressViewSegmentedBar : M13ProgressView 31 | 32 | /**@name Appearance*/ 33 | /**The direction of progress. (What direction the fill proceeds in.)*/ 34 | @property (nonatomic, assign) M13ProgressViewSegmentedBarProgressDirection progressDirection; 35 | /**The shape of the segments.*/ 36 | @property (nonatomic, assign) M13ProgressViewSegmentedBarSegmentShape segmentShape; 37 | /**The corner radius of the segment shape if the shape is set to M13ProgressViewSegmentedBarSegmentShapeRoundedRect.*/ 38 | @property (nonatomic, assign) CGFloat cornerRadius; 39 | /**The number of segments to display in the progress view.*/ 40 | @property (nonatomic, assign) NSInteger numberOfSegments; 41 | /**The separation between segments in points. Must be less than self.width / numberOfSegments.*/ 42 | @property (nonatomic, assign) CGFloat segmentSeparation; 43 | /**@name Actions*/ 44 | /**The color the bar changes to for the success action.*/ 45 | @property (nonatomic, retain) UIColor *successColor; 46 | /**The color the bar changes to for the failure action.*/ 47 | @property (nonatomic, retain) UIColor *failureColor; 48 | /**The array of UIColors that the segments will be colored with. 49 | @note Each index in the array coresponds to a single segment. If there are more indicies then segments, not all colors will be used. If there are less indicies than segments, the colors will be looped. If nil, then a solid fill will be used.*/ 50 | @property (nonatomic, retain) NSArray *primaryColors; 51 | /**The array of UIColors that the segment's backgrounds will be colored with. 52 | @note Each index in the array coresponds to a single segment. If there are more indicies then segments, not all colors will be used. If there are less indicies than segments, the colors will be looped. If nil, then a solid fill will be used.*/ 53 | @property (nonatomic, retain) NSArray *secondaryColors; 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewSegmentedRing.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressVewSegmentedRing.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | typedef enum { 15 | M13ProgressViewSegmentedRingSegmentBoundaryTypeWedge, 16 | M13ProgressViewSegmentedRingSegmentBoundaryTypeRectangle 17 | } M13ProgressViewSegmentedRingSegmentBoundaryType; 18 | 19 | #import "M13ProgressView.h" 20 | 21 | /**Progress is shown by a ring split up into segments.*/ 22 | @interface M13ProgressViewSegmentedRing : M13ProgressView 23 | 24 | /**@name Appearance*/ 25 | /**The width of the progress ring in points.*/ 26 | @property (nonatomic, assign) CGFloat progressRingWidth; 27 | /**The number of segments to display in the progress view.*/ 28 | @property (nonatomic, assign) NSInteger numberOfSegments; 29 | /**The angle of the separation between the segments in radians.*/ 30 | @property (nonatomic, assign) CGFloat segmentSeparationAngle; 31 | /**The type of boundary between segments.*/ 32 | @property (nonatomic, assign) M13ProgressViewSegmentedRingSegmentBoundaryType segmentBoundaryType; 33 | /**@name Percentage*/ 34 | /**Wether or not to display a percentage inside the ring.*/ 35 | @property (nonatomic, assign) BOOL showPercentage; 36 | 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /BGNetworkDemo/M13ProgressSuite/ProgressViews/M13ProgressViewStripedBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // M13ProgressViewStripedBar.h 3 | // M13ProgressView 4 | // 5 | /*Copyright (c) 2013 Brandon McQuilkin 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #import "M13ProgressView.h" 15 | 16 | typedef enum { 17 | M13ProgressViewStripedBarCornerTypeSquare, 18 | M13ProgressViewStripedBarCornerTypeRounded, 19 | M13ProgressViewStripedBarCornerTypeCircle 20 | } M13ProgressViewStripedBarCornerType; 21 | 22 | /**A progress bar that is striped, and can animate the stripes if desired.*/ 23 | @interface M13ProgressViewStripedBar : M13ProgressView 24 | 25 | /**@name Appearance*/ 26 | /**The type of corner to display on the bar.*/ 27 | @property (nonatomic, assign) M13ProgressViewStripedBarCornerType cornerType; 28 | /**The radius of the corner if the corner type is set to rounded rect.*/ 29 | @property (nonatomic, assign) CGFloat cornerRadius; 30 | /**The width of the stripes if shown.*/ 31 | @property (nonatomic, assign) CGFloat stripeWidth; 32 | /**Wether or not the stripes are animated.*/ 33 | @property (nonatomic, assign) BOOL animateStripes; 34 | /**Wether or not to show the stripes.*/ 35 | @property (nonatomic, assign) BOOL showStripes; 36 | /**The color of the stripes.*/ 37 | @property (nonatomic, retain) UIColor *stripeColor; 38 | /**The width of the border.*/ 39 | @property (nonatomic, assign) CGFloat borderWidth; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /BGNetworkDemo/Macro/LayoutMacro.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSLayoutMacro.h 3 | // 4 | // 5 | // Created by 家伟 李 on 14-5-5. 6 | // 7 | 8 | #ifndef LayoutMacro_PrLayoutMacro_h 9 | #define LayoutMacro_PrLayoutMacro_h 10 | 11 | #define kMainScreenWidth ([UIScreen mainScreen].applicationFrame).size.width //应用程序的宽度 12 | #define kMainScreenHeight ([UIScreen mainScreen].applicationFrame).size.height //应用程序的高度 13 | #define kMainBoundsHeight ([UIScreen mainScreen].bounds).size.height //屏幕的高度 14 | #define kMainBoundsWidth ([UIScreen mainScreen].bounds).size.width //屏幕的宽度 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /BGNetworkDemo/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 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Base/BaseModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseModel.h 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "Jastor.h" 10 | 11 | @interface BaseModel : Jastor 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Base/BaseModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseModel.m 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BaseModel.h" 10 | 11 | @implementation BaseModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Base/Jastor/Jastor-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Jastor' target in the 'Jastor' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Base/Jastor/Jastor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Jastor.h 3 | // Jastor 4 | // 5 | // Created by Elad Ossadon on 12/14/11. 6 | // http://devign.me | http://elad.ossadon.com | http://twitter.com/elado 7 | // 8 | #import 9 | 10 | @interface Jastor : NSObject 11 | 12 | @property (nonatomic, copy) NSString *objectId; 13 | /** 14 | * 解析字典 15 | */ 16 | + (id)objectFromDictionary:(NSDictionary*)dictionary; 17 | - (id)initWithDictionary:(NSDictionary *)dictionary; 18 | /** 19 | * 解析数组 20 | */ 21 | + (id)objectFromArray:(NSArray*)array; 22 | - (id)initWithArray:(NSArray *)array; 23 | 24 | 25 | /** 26 | * 解析数组成一系列由对象组成的数组 27 | * 28 | * @param array json数据的数组 29 | * 30 | * @return 返回解析好的model数组 31 | */ 32 | + (NSArray *)objectArrayFromDataArray:(NSArray *)array; 33 | 34 | - (NSMutableDictionary *)toDictionary; 35 | -(NSDictionary*)attrMapDict; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Base/Jastor/JastorRuntimeHelper.h: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface JastorRuntimeHelper : NSObject { 5 | 6 | } 7 | + (BOOL)isPropertyReadOnly:(Class)klass propertyName:(NSString*)propertyName; 8 | + (Class)propertyClassForPropertyName:(NSString *)propertyName ofClass:(Class)klass; 9 | + (NSArray *)propertyNames:(Class)klass; 10 | 11 | /** 属性修饰符是否是copy **/ 12 | + (BOOL)isPropertyCopyOfClass:(Class)klass propertyName:(NSString *)propertyName; 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Base/Jastor/JastorRuntimeHelper.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "JastorRuntimeHelper.h" 3 | #import "Jastor.h" 4 | 5 | static const char *property_getTypeName(objc_property_t property) { 6 | const char *attributes = property_getAttributes(property); 7 | char buffer[1 + strlen(attributes)]; 8 | strcpy(buffer, attributes); 9 | char *state = buffer, *attribute; 10 | while ((attribute = strsep(&state, ",")) != NULL) { 11 | if (attribute[0] == 'T') { 12 | size_t len = strlen(attribute); 13 | attribute[len - 1] = '\0'; 14 | return (const char *)[[NSData dataWithBytes:(attribute + 3) length:len - 2] bytes]; 15 | } 16 | } 17 | return "@"; 18 | } 19 | 20 | @implementation JastorRuntimeHelper 21 | 22 | static NSMutableDictionary *propertyListByClass; 23 | static NSMutableDictionary *propertyClassByClassAndPropertyName; 24 | + (BOOL)isPropertyReadOnly:(Class)klass propertyName:(NSString*)propertyName{ 25 | const char * type = property_getAttributes(class_getProperty(klass, [propertyName UTF8String])); 26 | NSString * typeString = [NSString stringWithUTF8String:type]; 27 | NSArray * attributes = [typeString componentsSeparatedByString:@","]; 28 | NSString * typeAttribute = [attributes objectAtIndex:1]; 29 | 30 | return [typeAttribute rangeOfString:@"R"].length > 0; 31 | } 32 | 33 | + (BOOL)isPropertyCopyOfClass:(Class)klass propertyName:(NSString *)propertyName{ 34 | const char * type = property_getAttributes(class_getProperty(klass, [propertyName UTF8String])); 35 | NSString *typeString = [NSString stringWithUTF8String:type]; 36 | //判断是否含有用逗号分隔的字符'C'的组 37 | if([typeString rangeOfString:@",C,"].location != NSNotFound){ 38 | return YES; 39 | } 40 | return NO; 41 | } 42 | 43 | + (NSArray *)propertyNames:(Class)klass { 44 | if (klass == [Jastor class]) { 45 | return [NSArray array]; 46 | } 47 | if (!propertyListByClass) { 48 | propertyListByClass = [[NSMutableDictionary alloc] init]; 49 | } 50 | 51 | NSString *className = NSStringFromClass(klass); 52 | NSArray *value = [propertyListByClass objectForKey:className]; 53 | 54 | if (value) { 55 | return value; 56 | } 57 | 58 | NSMutableArray *propertyNamesArray = [NSMutableArray array]; 59 | unsigned int propertyCount = 0; 60 | objc_property_t *properties = class_copyPropertyList(klass, &propertyCount); 61 | 62 | for (unsigned int i = 0; i < propertyCount; ++i) { 63 | objc_property_t property = properties[i]; 64 | const char * name = property_getName(property); 65 | 66 | [propertyNamesArray addObject:[NSString stringWithUTF8String:name]]; 67 | } 68 | [propertyListByClass setObject:propertyNamesArray forKey:className]; 69 | NSArray* arr = [JastorRuntimeHelper propertyNames:class_getSuperclass(klass)]; 70 | [propertyNamesArray addObjectsFromArray:arr]; 71 | free(properties); 72 | return propertyNamesArray; 73 | } 74 | 75 | + (Class)propertyClassForPropertyName:(NSString *)propertyName ofClass:(Class)klass { 76 | if (!propertyClassByClassAndPropertyName) { 77 | propertyClassByClassAndPropertyName = [[NSMutableDictionary alloc] init]; 78 | } 79 | 80 | NSString *key = [NSString stringWithFormat:@"%@:%@", NSStringFromClass(klass), propertyName]; 81 | NSString *value = [propertyClassByClassAndPropertyName objectForKey:key]; 82 | 83 | if (value) { 84 | return NSClassFromString(value); 85 | } 86 | 87 | unsigned int propertyCount = 0; 88 | objc_property_t *properties = class_copyPropertyList(klass, &propertyCount); 89 | 90 | const char * cPropertyName = [propertyName UTF8String]; 91 | 92 | for (unsigned int i = 0; i < propertyCount; ++i) { 93 | objc_property_t property = properties[i]; 94 | const char * name = property_getName(property); 95 | if (strcmp(cPropertyName, name) == 0) { 96 | free(properties); 97 | 98 | //by lipeng. for stability. 99 | const char* propertyTypeName = property_getTypeName(property); 100 | if(propertyTypeName == NULL || propertyTypeName[0] == '\0'){ 101 | return nil; 102 | } 103 | NSString *className = [NSString stringWithUTF8String:propertyTypeName]; 104 | [propertyClassByClassAndPropertyName setObject:className forKey:key]; 105 | //we found the property - we need to free 106 | return NSClassFromString(className); 107 | } 108 | } 109 | free(properties); 110 | //this will support traversing the inheritance chain 111 | return [self propertyClassForPropertyName:propertyName ofClass:class_getSuperclass(klass)]; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Demo/DemoModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoModel.h 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BaseModel.h" 10 | 11 | @interface DemoModel : BaseModel 12 | @property (nonatomic, copy) NSString *name; //人名 13 | @property (nonatomic, assign) NSInteger age; //年龄 14 | @property (nonatomic, assign) NSInteger sex; //性别,0:未知 1:男 2:女 15 | @end 16 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Demo/DemoModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoModel.m 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "DemoModel.h" 10 | 11 | @implementation DemoModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Demo/PageModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // PageModel.h 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BaseModel.h" 10 | 11 | @interface PageModel : BaseModel 12 | @property (nonatomic, assign) NSInteger count; 13 | @property (nonatomic, strong) NSArray *list; 14 | @end 15 | -------------------------------------------------------------------------------- /BGNetworkDemo/Models/Demo/PageModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // PageModel.m 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "PageModel.h" 10 | #import "DemoModel.h" 11 | 12 | @implementation PageModel 13 | + (Class)list_class{ 14 | return [DemoModel class]; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/AdvertInfoRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // AdvertInfoRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BGNetworkRequest.h" 10 | 11 | @interface AdvertInfoRequest : BGNetworkRequest 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/AdvertInfoRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // AdvertInfoRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "AdvertInfoRequest.h" 10 | 11 | @implementation AdvertInfoRequest 12 | - (instancetype)init { 13 | if(self = [super init]) { 14 | self.methodName = @"advert.php"; 15 | self.httpMethod = BGNetworkRequestHTTPGet; 16 | } 17 | return self; 18 | } 19 | @end 20 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/DemoNetworkConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoNetworkConfiguration.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BGNetworkConfiguration.h" 10 | 11 | @interface DemoNetworkConfiguration : BGNetworkConfiguration 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/DemoNetworkConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoNetworkConfiguration.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "DemoNetworkConfiguration.h" 10 | 11 | @implementation DemoNetworkConfiguration 12 | - (NSString *)baseURLString{ 13 | // return @"http://localhost/app/BGNetwork/"; 14 | return @"http://casetree.cn/web/test/"; 15 | // return @"https://casetree.cn/web/test/"; 16 | } 17 | 18 | - (NSData *)httpBodyDataWithRequest:(BGNetworkRequest *)request{ 19 | if(!request.parametersDic.count){ 20 | return nil; 21 | } 22 | NSDictionary *parametersDic = @{@"params":request.parametersDic}; 23 | NSError *error = nil; 24 | NSData *httpBody = [NSJSONSerialization dataWithJSONObject:parametersDic options: (NSJSONWritingOptions)0 error:&error]; 25 | if(error){ 26 | return nil; 27 | } 28 | return httpBody; 29 | } 30 | @end 31 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/DemoRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BGNetworkRequest.h" 10 | 11 | @interface DemoRequest : BGNetworkRequest 12 | - (instancetype)initPage:(NSInteger)page pageSize:(NSInteger)pageSize; 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/DemoRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "DemoRequest.h" 10 | #import "PageModel.h" 11 | 12 | @implementation DemoRequest 13 | 14 | #pragma mark - BGNetworkRequest method 15 | - (id)processResponseObject:(id)responseObject{ 16 | PageModel *model = [[PageModel alloc] initWithDictionary:responseObject[@"result"]]; 17 | return model; 18 | } 19 | 20 | #pragma mark - 21 | - (instancetype)initPage:(NSInteger)page pageSize:(NSInteger)pageSize{ 22 | if(self = [super init]){ 23 | self.methodName = @"demo.php"; 24 | self.httpMethod = BGNetworkRequestHTTPPost; 25 | self.cachePolicy = BGNetworkRquestCacheNone; 26 | //设置参数 27 | [self setValue:@"1196689" forParamKey:@"orderNo"]; 28 | [self setIntegerValue:page forParamKey:@"page"]; 29 | [self setIntegerValue:pageSize forParamKey:@"pageSize"]; 30 | [self setValue:@"test" forParamKey:@"test.demo"]; 31 | } 32 | return self; 33 | } 34 | @end 35 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/DownloadFileRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // DownloadFileRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/20. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGDownloadRequest.h" 10 | 11 | @interface DownloadFileRequest : BGDownloadRequest 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/DownloadFileRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // DownloadFileRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/20. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "DownloadFileRequest.h" 10 | 11 | @implementation DownloadFileRequest 12 | - (instancetype)init { 13 | if(self = [super init]) { 14 | self.methodName = @"download/CollectionViewPGforIOS.pdf?test=100"; 15 | self.fileName = @"test.pdf"; 16 | } 17 | return self; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/InfoRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // InfoRequest.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BGNetworkRequest.h" 10 | 11 | @interface InfoRequest : BGNetworkRequest 12 | - (instancetype)initWithId:(NSInteger)infoId; 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Network/InfoRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // InfoRequest.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "InfoRequest.h" 10 | 11 | @implementation InfoRequest 12 | 13 | - (instancetype)initWithId:(NSInteger)infoId { 14 | if(self = [super init]) { 15 | self.methodName = @"info.php"; 16 | self.httpMethod = BGNetworkRequestHTTPPost; 17 | [self setIntegerValue:infoId forParamKey:@"infoId"]; 18 | } 19 | return self; 20 | } 21 | @end 22 | -------------------------------------------------------------------------------- /BGNetworkDemo/Resource/icon_shanchu@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuchungui/BGNetwork/a1345c50735e73d7bf6d9c9627731fe1fcc8bcee/BGNetworkDemo/Resource/icon_shanchu@2x.png -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/NSData+ImageContentType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | @interface NSData (ImageContentType) 9 | 10 | /** 11 | * Compute the content type for an image data 12 | * 13 | * @param data the input data 14 | * 15 | * @return the content type as string (i.e. image/jpeg, image/gif) 16 | */ 17 | + (NSString *)sd_contentTypeForImageData:(NSData *)data; 18 | 19 | @end 20 | 21 | 22 | @interface NSData (ImageContentTypeDeprecated) 23 | 24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/NSData+ImageContentType.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import "NSData+ImageContentType.h" 7 | 8 | 9 | @implementation NSData (ImageContentType) 10 | 11 | + (NSString *)sd_contentTypeForImageData:(NSData *)data { 12 | uint8_t c; 13 | [data getBytes:&c length:1]; 14 | switch (c) { 15 | case 0xFF: 16 | return @"image/jpeg"; 17 | case 0x89: 18 | return @"image/png"; 19 | case 0x47: 20 | return @"image/gif"; 21 | case 0x49: 22 | case 0x4D: 23 | return @"image/tiff"; 24 | case 0x52: 25 | // R as RIFF for WEBP 26 | if ([data length] < 12) { 27 | return nil; 28 | } 29 | 30 | NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding]; 31 | if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) { 32 | return @"image/webp"; 33 | } 34 | 35 | return nil; 36 | } 37 | return nil; 38 | } 39 | 40 | @end 41 | 42 | 43 | @implementation NSData (ImageContentTypeDeprecated) 44 | 45 | + (NSString *)contentTypeForImageData:(NSData *)data { 46 | return [self sd_contentTypeForImageData:data]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImageCompat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * (c) Jamie Pinkham 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | #import 11 | 12 | #ifdef __OBJC_GC__ 13 | #error SDWebImage does not support Objective-C Garbage Collection 14 | #endif 15 | 16 | #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 17 | #error SDWebImage doesn't support Deployment Target version < 5.0 18 | #endif 19 | 20 | #if !TARGET_OS_IPHONE 21 | #import 22 | #ifndef UIImage 23 | #define UIImage NSImage 24 | #endif 25 | #ifndef UIImageView 26 | #define UIImageView NSImageView 27 | #endif 28 | #else 29 | 30 | #import 31 | 32 | #endif 33 | 34 | #ifndef NS_ENUM 35 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 36 | #endif 37 | 38 | #ifndef NS_OPTIONS 39 | #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type 40 | #endif 41 | 42 | #if OS_OBJECT_USE_OBJC 43 | #undef SDDispatchQueueRelease 44 | #undef SDDispatchQueueSetterSementics 45 | #define SDDispatchQueueRelease(q) 46 | #define SDDispatchQueueSetterSementics strong 47 | #else 48 | #undef SDDispatchQueueRelease 49 | #undef SDDispatchQueueSetterSementics 50 | #define SDDispatchQueueRelease(q) (dispatch_release(q)) 51 | #define SDDispatchQueueSetterSementics assign 52 | #endif 53 | 54 | extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image); 55 | 56 | typedef void(^SDWebImageNoParamsBlock)(); 57 | 58 | extern NSString *const SDWebImageErrorDomain; 59 | 60 | #define dispatch_main_sync_safe(block)\ 61 | if ([NSThread isMainThread]) {\ 62 | block();\ 63 | } else {\ 64 | dispatch_sync(dispatch_get_main_queue(), block);\ 65 | } 66 | 67 | #define dispatch_main_async_safe(block)\ 68 | if ([NSThread isMainThread]) {\ 69 | block();\ 70 | } else {\ 71 | dispatch_async(dispatch_get_main_queue(), block);\ 72 | } 73 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImageCompat.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDWebImageCompat.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 11/12/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "SDWebImageCompat.h" 10 | 11 | #if !__has_feature(objc_arc) 12 | #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag 13 | #endif 14 | 15 | inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { 16 | if (!image) { 17 | return nil; 18 | } 19 | 20 | if ([image.images count] > 0) { 21 | NSMutableArray *scaledImages = [NSMutableArray array]; 22 | 23 | for (UIImage *tempImage in image.images) { 24 | [scaledImages addObject:SDScaledImageForKey(key, tempImage)]; 25 | } 26 | 27 | return [UIImage animatedImageWithImages:scaledImages duration:image.duration]; 28 | } 29 | else { 30 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { 31 | CGFloat scale = [UIScreen mainScreen].scale; 32 | if (key.length >= 8) { 33 | NSRange range = [key rangeOfString:@"@2x."]; 34 | if (range.location != NSNotFound) { 35 | scale = 2.0; 36 | } 37 | 38 | range = [key rangeOfString:@"@3x."]; 39 | if (range.location != NSNotFound) { 40 | scale = 3.0; 41 | } 42 | } 43 | 44 | UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; 45 | image = scaledImage; 46 | } 47 | return image; 48 | } 49 | } 50 | 51 | NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain"; 52 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImageDecoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import 12 | #import "SDWebImageCompat.h" 13 | 14 | @interface UIImage (ForceDecode) 15 | 16 | + (UIImage *)decodedImageWithImage:(UIImage *)image; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImageDecoder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import "SDWebImageDecoder.h" 12 | 13 | @implementation UIImage (ForceDecode) 14 | 15 | + (UIImage *)decodedImageWithImage:(UIImage *)image { 16 | // do not decode animated images 17 | if (image.images) { return image; } 18 | 19 | CGImageRef imageRef = image.CGImage; 20 | 21 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 22 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 23 | alpha == kCGImageAlphaLast || 24 | alpha == kCGImageAlphaPremultipliedFirst || 25 | alpha == kCGImageAlphaPremultipliedLast); 26 | 27 | if (anyAlpha) { return image; } 28 | 29 | size_t width = CGImageGetWidth(imageRef); 30 | size_t height = CGImageGetHeight(imageRef); 31 | 32 | // current 33 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 34 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 35 | 36 | bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelIndexed); 37 | if (unsupportedColorSpace) 38 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 39 | 40 | CGContextRef context = CGBitmapContextCreate(NULL, width, 41 | height, 42 | CGImageGetBitsPerComponent(imageRef), 43 | 0, 44 | colorspaceRef, 45 | kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); 46 | 47 | // Draw the image into the context and retrieve the new image, which will now have an alpha layer 48 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 49 | CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context); 50 | UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha]; 51 | 52 | if (unsupportedColorSpace) 53 | CGColorSpaceRelease(colorspaceRef); 54 | 55 | CGContextRelease(context); 56 | CGImageRelease(imageRefWithAlpha); 57 | 58 | return imageWithAlpha; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImageDownloaderOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageDownloader.h" 11 | #import "SDWebImageOperation.h" 12 | 13 | extern NSString *const SDWebImageDownloadStartNotification; 14 | extern NSString *const SDWebImageDownloadReceiveResponseNotification; 15 | extern NSString *const SDWebImageDownloadStopNotification; 16 | extern NSString *const SDWebImageDownloadFinishNotification; 17 | 18 | @interface SDWebImageDownloaderOperation : NSOperation 19 | 20 | /** 21 | * The request used by the operation's connection. 22 | */ 23 | @property (strong, nonatomic, readonly) NSURLRequest *request; 24 | 25 | 26 | @property (assign, nonatomic) BOOL shouldDecompressImages; 27 | 28 | /** 29 | * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default. 30 | * 31 | * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`. 32 | */ 33 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage; 34 | 35 | /** 36 | * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. 37 | * 38 | * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. 39 | */ 40 | @property (nonatomic, strong) NSURLCredential *credential; 41 | 42 | /** 43 | * The SDWebImageDownloaderOptions for the receiver. 44 | */ 45 | @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options; 46 | 47 | /** 48 | * The expected size of data. 49 | */ 50 | @property (assign, nonatomic) NSInteger expectedSize; 51 | 52 | /** 53 | * The response returned by the operation's connection. 54 | */ 55 | @property (strong, nonatomic) NSURLResponse *response; 56 | 57 | /** 58 | * Initializes a `SDWebImageDownloaderOperation` object 59 | * 60 | * @see SDWebImageDownloaderOperation 61 | * 62 | * @param request the URL request 63 | * @param options downloader options 64 | * @param progressBlock the block executed when a new chunk of data arrives. 65 | * @note the progress block is executed on a background queue 66 | * @param completedBlock the block executed when the download is done. 67 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue 68 | * @param cancelBlock the block executed if the download (operation) is cancelled 69 | * 70 | * @return the initialized instance 71 | */ 72 | - (id)initWithRequest:(NSURLRequest *)request 73 | options:(SDWebImageDownloaderOptions)options 74 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 75 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock 76 | cancelled:(SDWebImageNoParamsBlock)cancelBlock; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImageOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | 11 | @protocol SDWebImageOperation 12 | 13 | - (void)cancel; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/SDWebImagePrefetcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageManager.h" 11 | 12 | @class SDWebImagePrefetcher; 13 | 14 | @protocol SDWebImagePrefetcherDelegate 15 | 16 | @optional 17 | 18 | /** 19 | * Called when an image was prefetched. 20 | * 21 | * @param imagePrefetcher The current image prefetcher 22 | * @param imageURL The image url that was prefetched 23 | * @param finishedCount The total number of images that were prefetched (successful or not) 24 | * @param totalCount The total number of images that were to be prefetched 25 | */ 26 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; 27 | 28 | /** 29 | * Called when all images are prefetched. 30 | * @param imagePrefetcher The current image prefetcher 31 | * @param totalCount The total number of images that were prefetched (whether successful or not) 32 | * @param skippedCount The total number of images that were skipped 33 | */ 34 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; 35 | 36 | @end 37 | 38 | typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); 39 | typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls); 40 | 41 | /** 42 | * Prefetch some URLs in the cache for future use. Images are downloaded in low priority. 43 | */ 44 | @interface SDWebImagePrefetcher : NSObject 45 | 46 | /** 47 | * The web image manager 48 | */ 49 | @property (strong, nonatomic, readonly) SDWebImageManager *manager; 50 | 51 | /** 52 | * Maximum number of URLs to prefetch at the same time. Defaults to 3. 53 | */ 54 | @property (nonatomic, assign) NSUInteger maxConcurrentDownloads; 55 | 56 | /** 57 | * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority. 58 | */ 59 | @property (nonatomic, assign) SDWebImageOptions options; 60 | 61 | /** 62 | * Queue options for Prefetcher. Defaults to Main Queue. 63 | */ 64 | @property (nonatomic, assign) dispatch_queue_t prefetcherQueue; 65 | 66 | @property (weak, nonatomic) id delegate; 67 | 68 | /** 69 | * Return the global image prefetcher instance. 70 | */ 71 | + (SDWebImagePrefetcher *)sharedImagePrefetcher; 72 | 73 | /** 74 | * Allows you to instantiate a prefetcher with any arbitrary image manager. 75 | */ 76 | - (id)initWithImageManager:(SDWebImageManager *)manager; 77 | 78 | /** 79 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, 80 | * currently one image is downloaded at a time, 81 | * and skips images for failed downloads and proceed to the next image in the list 82 | * 83 | * @param urls list of URLs to prefetch 84 | */ 85 | - (void)prefetchURLs:(NSArray *)urls; 86 | 87 | /** 88 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, 89 | * currently one image is downloaded at a time, 90 | * and skips images for failed downloads and proceed to the next image in the list 91 | * 92 | * @param urls list of URLs to prefetch 93 | * @param progressBlock block to be called when progress updates; 94 | * first parameter is the number of completed (successful or not) requests, 95 | * second parameter is the total number of images originally requested to be prefetched 96 | * @param completionBlock block to be called when prefetching is completed 97 | * first param is the number of completed (successful or not) requests, 98 | * second parameter is the number of skipped requests 99 | */ 100 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock; 101 | 102 | /** 103 | * Remove and cancel queued list 104 | */ 105 | - (void)cancelPrefetching; 106 | 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIImage+GIF.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GIF.h 3 | // LBGIFImage 4 | // 5 | // Created by Laurin Brandner on 06.01.12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (GIF) 12 | 13 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name; 14 | 15 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data; 16 | 17 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIImage+MultiFormat.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.h 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (MultiFormat) 12 | 13 | + (UIImage *)sd_imageWithData:(NSData *)data; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIImage+MultiFormat.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "UIImage+MultiFormat.h" 10 | #import "UIImage+GIF.h" 11 | #import "NSData+ImageContentType.h" 12 | #import 13 | 14 | #ifdef SD_WEBP 15 | #import "UIImage+WebP.h" 16 | #endif 17 | 18 | @implementation UIImage (MultiFormat) 19 | 20 | + (UIImage *)sd_imageWithData:(NSData *)data { 21 | if (!data) { 22 | return nil; 23 | } 24 | 25 | UIImage *image; 26 | NSString *imageContentType = [NSData sd_contentTypeForImageData:data]; 27 | if ([imageContentType isEqualToString:@"image/gif"]) { 28 | image = [UIImage sd_animatedGIFWithData:data]; 29 | } 30 | #ifdef SD_WEBP 31 | else if ([imageContentType isEqualToString:@"image/webp"]) 32 | { 33 | image = [UIImage sd_imageWithWebPData:data]; 34 | } 35 | #endif 36 | else { 37 | image = [[UIImage alloc] initWithData:data]; 38 | UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data]; 39 | if (orientation != UIImageOrientationUp) { 40 | image = [UIImage imageWithCGImage:image.CGImage 41 | scale:image.scale 42 | orientation:orientation]; 43 | } 44 | } 45 | 46 | 47 | return image; 48 | } 49 | 50 | 51 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { 52 | UIImageOrientation result = UIImageOrientationUp; 53 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); 54 | if (imageSource) { 55 | CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); 56 | if (properties) { 57 | CFTypeRef val; 58 | int exifOrientation; 59 | val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); 60 | if (val) { 61 | CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); 62 | result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; 63 | } // else - if it's not set it remains at up 64 | CFRelease((CFTypeRef) properties); 65 | } else { 66 | //NSLog(@"NO PROPERTIES, FAIL"); 67 | } 68 | CFRelease(imageSource); 69 | } 70 | return result; 71 | } 72 | 73 | #pragma mark EXIF orientation tag converter 74 | // Convert an EXIF image orientation to an iOS one. 75 | // reference see here: http://sylvana.net/jpegcrop/exif_orientation.html 76 | + (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation { 77 | UIImageOrientation orientation = UIImageOrientationUp; 78 | switch (exifOrientation) { 79 | case 1: 80 | orientation = UIImageOrientationUp; 81 | break; 82 | 83 | case 3: 84 | orientation = UIImageOrientationDown; 85 | break; 86 | 87 | case 8: 88 | orientation = UIImageOrientationLeft; 89 | break; 90 | 91 | case 6: 92 | orientation = UIImageOrientationRight; 93 | break; 94 | 95 | case 2: 96 | orientation = UIImageOrientationUpMirrored; 97 | break; 98 | 99 | case 4: 100 | orientation = UIImageOrientationDownMirrored; 101 | break; 102 | 103 | case 5: 104 | orientation = UIImageOrientationLeftMirrored; 105 | break; 106 | 107 | case 7: 108 | orientation = UIImageOrientationRightMirrored; 109 | break; 110 | default: 111 | break; 112 | } 113 | return orientation; 114 | } 115 | 116 | 117 | 118 | @end 119 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIImage+WebP.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.h 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #ifdef SD_WEBP 10 | 11 | #import 12 | 13 | // Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device 14 | void WebPInitPremultiplyNEON(void); 15 | 16 | void WebPInitUpsamplersNEON(void); 17 | 18 | void VP8DspInitNEON(void); 19 | 20 | @interface UIImage (WebP) 21 | 22 | + (UIImage *)sd_imageWithWebPData:(NSData *)data; 23 | 24 | @end 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIImage+WebP.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #ifdef SD_WEBP 10 | #import "UIImage+WebP.h" 11 | 12 | #if !COCOAPODS 13 | #import "webp/decode.h" 14 | #else 15 | #import "libwebp/webp/decode.h" 16 | #endif 17 | 18 | // Callback for CGDataProviderRelease 19 | static void FreeImageData(void *info, const void *data, size_t size) 20 | { 21 | free((void *)data); 22 | } 23 | 24 | @implementation UIImage (WebP) 25 | 26 | + (UIImage *)sd_imageWithWebPData:(NSData *)data { 27 | WebPDecoderConfig config; 28 | if (!WebPInitDecoderConfig(&config)) { 29 | return nil; 30 | } 31 | 32 | if (WebPGetFeatures(data.bytes, data.length, &config.input) != VP8_STATUS_OK) { 33 | return nil; 34 | } 35 | 36 | config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB; 37 | config.options.use_threads = 1; 38 | 39 | // Decode the WebP image data into a RGBA value array. 40 | if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK) { 41 | return nil; 42 | } 43 | 44 | int width = config.input.width; 45 | int height = config.input.height; 46 | if (config.options.use_scaling) { 47 | width = config.options.scaled_width; 48 | height = config.options.scaled_height; 49 | } 50 | 51 | // Construct a UIImage from the decoded RGBA value array. 52 | CGDataProviderRef provider = 53 | CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData); 54 | CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 55 | CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0; 56 | size_t components = config.input.has_alpha ? 4 : 3; 57 | CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; 58 | CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); 59 | 60 | CGColorSpaceRelease(colorSpaceRef); 61 | CGDataProviderRelease(provider); 62 | 63 | UIImage *image = [[UIImage alloc] initWithCGImage:imageRef]; 64 | CGImageRelease(imageRef); 65 | 66 | return image; 67 | } 68 | 69 | @end 70 | 71 | #if !COCOAPODS 72 | // Functions to resolve some undefined symbols when using WebP and force_load flag 73 | void WebPInitPremultiplyNEON(void) {} 74 | void WebPInitUpsamplersNEON(void) {} 75 | void VP8DspInitNEON(void) {} 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIView+WebCacheOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageManager.h" 11 | 12 | @interface UIView (WebCacheOperation) 13 | 14 | /** 15 | * Set the image load operation (storage in a UIView based dictionary) 16 | * 17 | * @param operation the operation 18 | * @param key key for storing the operation 19 | */ 20 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key; 21 | 22 | /** 23 | * Cancel all operations for the current UIView and key 24 | * 25 | * @param key key for identifying the operations 26 | */ 27 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key; 28 | 29 | /** 30 | * Just remove the operations corresponding to the current UIView and key without cancelling them 31 | * 32 | * @param key key for identifying the operations 33 | */ 34 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /BGNetworkDemo/SDWebImage/UIView+WebCacheOperation.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIView+WebCacheOperation.h" 10 | #import "objc/runtime.h" 11 | 12 | static char loadOperationKey; 13 | 14 | @implementation UIView (WebCacheOperation) 15 | 16 | - (NSMutableDictionary *)operationDictionary { 17 | NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey); 18 | if (operations) { 19 | return operations; 20 | } 21 | operations = [NSMutableDictionary dictionary]; 22 | objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 23 | return operations; 24 | } 25 | 26 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key { 27 | [self sd_cancelImageLoadOperationWithKey:key]; 28 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 29 | [operationDictionary setObject:operation forKey:key]; 30 | } 31 | 32 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key { 33 | // Cancel in progress downloader from queue 34 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 35 | id operations = [operationDictionary objectForKey:key]; 36 | if (operations) { 37 | if ([operations isKindOfClass:[NSArray class]]) { 38 | for (id operation in operations) { 39 | if (operation) { 40 | [operation cancel]; 41 | } 42 | } 43 | } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){ 44 | [(id) operations cancel]; 45 | } 46 | [operationDictionary removeObjectForKey:key]; 47 | } 48 | } 49 | 50 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key { 51 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 52 | [operationDictionary removeObjectForKey:key]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /BGNetworkDemo/UIView+Extra.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Extra.h 3 | // CropAvatarImgDemo 4 | // 5 | // Created by 杨社兵 on 15/8/23. 6 | // Copyright (c) 2015年 FAL. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Extra) 12 | 13 | /** 14 | * Sets the current view of "origin" attribute directly 15 | * Mean view.frame.origin = origin; 16 | */ 17 | @property CGPoint origin; 18 | 19 | /** 20 | * Sets the current view of "size" attribute directly 21 | * Means view.frame.size = size; 22 | */ 23 | @property CGSize size; 24 | 25 | /** 26 | * Sets the current view of "height" attribute directly 27 | * Means view.frame.size.height = height; 28 | */ 29 | @property CGFloat height; 30 | 31 | /** 32 | * Sets the current view of "width" attribute directly 33 | * Means view.frame.size.width = width; 34 | */ 35 | @property CGFloat width; 36 | 37 | /** 38 | * Sets the current view of "top" attribute directly 39 | * Means view.frame.origin.y = top; 40 | */ 41 | @property CGFloat top; 42 | 43 | /** 44 | * Sets the current view of "left" attribute directly 45 | * Means view.frame.origin.x = left; 46 | */ 47 | @property CGFloat left; 48 | 49 | /** 50 | * Sets the current view of "bottom" attribute directly 51 | * Means view.frame.origin.y + view.frame.size.height = bottom; 52 | */ 53 | @property CGFloat bottom; 54 | 55 | /** 56 | * Sets the current view of "right" attribute directly 57 | * Means view.frame.origin.x + view.frame.size.width = right; 58 | */ 59 | @property CGFloat right; 60 | 61 | /** 62 | * Sets the current view of "centerX" attribute directly 63 | * Means view.center.x = centerX; 64 | */ 65 | 66 | @property (nonatomic) CGFloat centerX; 67 | 68 | /** 69 | * Sets the current view of "centerY" attribute directly 70 | * Means view.center.y = centerY; 71 | */ 72 | @property (nonatomic) CGFloat centerY; 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /BGNetworkDemo/UIView+Extra.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Extra.m 3 | // CropAvatarImgDemo 4 | // 5 | // Created by 杨社兵 on 15/8/23. 6 | // Copyright (c) 2015年 FAL. All rights reserved. 7 | // 8 | 9 | #import "UIView+Extra.h" 10 | 11 | @implementation UIView (Extra) 12 | 13 | - (CGPoint)origin 14 | { 15 | return self.frame.origin; 16 | } 17 | 18 | - (void)setOrigin:(CGPoint)point 19 | { 20 | CGRect tempFrame = self.frame; 21 | tempFrame.origin = point; 22 | self.frame = tempFrame; 23 | } 24 | 25 | - (CGSize)size 26 | { 27 | return self.frame.size; 28 | } 29 | 30 | - (void)setSize:(CGSize)tempSize 31 | { 32 | CGRect tempFrame = self.frame; 33 | tempFrame.size = tempSize; 34 | self.frame = tempFrame; 35 | } 36 | 37 | - (CGFloat)height 38 | { 39 | return self.frame.size.height; 40 | } 41 | 42 | - (void)setHeight:(CGFloat)tempHeight 43 | { 44 | CGRect tempFrame = self.frame; 45 | tempFrame.size.height = tempHeight; 46 | self.frame = tempFrame; 47 | } 48 | 49 | - (CGFloat)width 50 | { 51 | return self.frame.size.width; 52 | } 53 | 54 | - (void)setWidth:(CGFloat)tempWidth 55 | { 56 | CGRect tempFrame = self.frame; 57 | tempFrame.size.width = tempWidth; 58 | self.frame = tempFrame; 59 | } 60 | 61 | - (CGFloat)top 62 | { 63 | return self.frame.origin.y; 64 | } 65 | 66 | - (void)setTop:(CGFloat)tempTop 67 | { 68 | CGRect tempFrame = self.frame; 69 | tempFrame.origin.y = tempTop; 70 | self.frame = tempFrame; 71 | } 72 | 73 | - (CGFloat)left 74 | { 75 | return self.frame.origin.x; 76 | } 77 | 78 | - (void)setLeft:(CGFloat)tempLeft 79 | { 80 | CGRect tempFrame = self.frame; 81 | tempFrame.origin.x = tempLeft; 82 | self.frame = tempFrame; 83 | } 84 | 85 | - (CGFloat)bottom 86 | { 87 | return self.frame.origin.y + self.frame.size.height; 88 | } 89 | 90 | - (void)setBottom:(CGFloat)tempBottom 91 | { 92 | CGRect tempFrame = self.frame; 93 | tempFrame.origin.y = tempBottom - self.frame.size.height; 94 | self.frame = tempFrame; 95 | } 96 | 97 | - (CGFloat)right 98 | { 99 | return self.frame.origin.x + self.frame.size.width; 100 | } 101 | 102 | - (void)setRight:(CGFloat)tempRight 103 | { 104 | CGRect tempFrame = self.frame; 105 | tempFrame.origin.x = tempRight - tempFrame.size.width ; 106 | self.frame = tempFrame; 107 | } 108 | 109 | - (CGFloat)centerX { 110 | return self.center.x; 111 | } 112 | 113 | - (void)setCenterX:(CGFloat)centerX { 114 | self.center = CGPointMake(centerX, self.center.y); 115 | } 116 | 117 | - (CGFloat)centerY { 118 | return self.center.y; 119 | } 120 | 121 | - (void)setCenterY:(CGFloat)centerY { 122 | self.center = CGPointMake(self.center.x, centerY); 123 | } 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Base/BaseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseViewController.h 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BaseViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Base/BaseViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseViewController.m 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BaseViewController.h" 10 | 11 | @interface BaseViewController () 12 | 13 | @end 14 | 15 | @implementation BaseViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | self.edgesForExtendedLayout = UIRectEdgeNone; 20 | self.extendedLayoutIncludesOpaqueBars = NO; 21 | self.automaticallyAdjustsScrollViewInsets = NO; 22 | // Do any additional setup after loading the view. 23 | } 24 | 25 | - (void)didReceiveMemoryWarning { 26 | [super didReceiveMemoryWarning]; 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | /* 31 | #pragma mark - Navigation 32 | 33 | // In a storyboard-based application, you will often want to do a little preparation before navigation 34 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 35 | // Get the new view controller using [segue destinationViewController]. 36 | // Pass the selected object to the new view controller. 37 | } 38 | */ 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGBatchViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGBatchViewController.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BGBatchViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGBatchViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGBatchViewController.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BGBatchViewController.h" 10 | #import "InfoRequest.h" 11 | #import "AdvertInfoRequest.h" 12 | #import "BGBatchRequest.h" 13 | 14 | @interface BGBatchViewController () 15 | @property (weak, nonatomic) IBOutlet UILabel *textLabel; 16 | 17 | @end 18 | 19 | @implementation BGBatchViewController 20 | - (void)dealloc { 21 | NSLog(@"%@ delloc", NSStringFromClass(self.class)); 22 | } 23 | 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | // Do any additional setup after loading the view from its nib. 27 | } 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | - (IBAction)sendRequestAction:(id)sender { 35 | //clear 36 | self.textLabel.text = @""; 37 | 38 | //create request 39 | InfoRequest *infoRequest = [[InfoRequest alloc] initWithId:13]; 40 | AdvertInfoRequest *advertRequest = [[AdvertInfoRequest alloc] init]; 41 | 42 | BGBatchRequest *batchRequest = [[BGBatchRequest alloc] initWithRequests:@[infoRequest, advertRequest]]; 43 | batchRequest.continueLoadWhenRequestFailure = YES; 44 | 45 | //set failure block 46 | [batchRequest setBusinessFailure:^(BGNetworkRequest *request, id response) { 47 | self.textLabel.text = [NSString stringWithFormat:@"%@\n\n%@:%@", self.textLabel.text, NSStringFromClass(request.class), response]; 48 | } networkFailure:^(BGNetworkRequest *request, NSError *error) { 49 | self.textLabel.text = [NSString stringWithFormat:@"%@\n\n%@:%@", self.textLabel.text, NSStringFromClass(request.class), error]; 50 | }]; 51 | 52 | //send request 53 | [batchRequest sendRequestSuccess:^(BGNetworkRequest *request, id response) { 54 | self.textLabel.text = [NSString stringWithFormat:@"%@\n\n%@:%@", self.textLabel.text, NSStringFromClass(request.class), response]; 55 | } completion:^(BGBatchRequest *batchRequest, BOOL isSuccess) { 56 | NSString *finishTip = @""; 57 | if(isSuccess) { 58 | finishTip = @"Success!"; 59 | } 60 | else { 61 | finishTip = @"Failure!"; 62 | } 63 | self.textLabel.text = [NSString stringWithFormat:@"%@\n\n%@", self.textLabel.text, finishTip]; 64 | }]; 65 | } 66 | 67 | /* 68 | #pragma mark - Navigation 69 | 70 | // In a storyboard-based application, you will often want to do a little preparation before navigation 71 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 72 | // Get the new view controller using [segue destinationViewController]. 73 | // Pass the selected object to the new view controller. 74 | } 75 | */ 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGBatchViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGDownloadRequestController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGDownloadRequestController.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/12. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BaseViewController.h" 10 | 11 | @interface BGDownloadRequestController : BaseViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGDownloadRequestController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGDownloadRequestController.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/12. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGDownloadRequestController.h" 10 | #import "AFNetworking.h" 11 | #import "DownloadFileRequest.h" 12 | #import "BGNetwork.h" 13 | #import "M13ProgressViewRing.h" 14 | 15 | NSString *EncodingURL(NSString * string) { 16 | return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, 17 | (CFStringRef)string, 18 | NULL, 19 | (CFStringRef)@"!*'();:@&=+$,/?%#[]", 20 | kCFStringEncodingUTF8)); 21 | } 22 | 23 | #define PATH_AT_CACHEDIR(name) [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] 24 | 25 | @interface BGDownloadRequestController () 26 | @property (weak, nonatomic) IBOutlet M13ProgressViewRing *progressViewRing; 27 | @property (weak, nonatomic) IBOutlet UIButton *downloadButton; 28 | @property (weak, nonatomic) IBOutlet UIButton *cancelButton; 29 | @property (weak, nonatomic) IBOutlet UIWebView *webView; 30 | 31 | @property (nonatomic, strong) BGDownloadRequest *request; 32 | @end 33 | 34 | @implementation BGDownloadRequestController 35 | 36 | - (void)viewDidLoad { 37 | [super viewDidLoad]; 38 | [self.progressViewRing setProgress:0 animated:YES]; 39 | // Do any additional setup after loading the view from its nib. 40 | } 41 | 42 | - (void)viewWillDisappear:(BOOL)animated { 43 | [super viewWillDisappear:animated]; 44 | [self.request cancelRequest]; 45 | } 46 | 47 | - (IBAction)downloadFileAction:(id)sender { 48 | BGDownloadRequest *request = [[BGDownloadRequest alloc] init]; 49 | request.methodName = @"http://casetree.cn/web/test/download/CollectionViewPGforIOS.pdf?test=100"; 50 | request.fileName = @"test.pdf"; 51 | [request sendRequestWithProgress:^(NSProgress * _Nonnull downloadProgress) { 52 | dispatch_async(dispatch_get_main_queue(), ^{ 53 | [self.progressViewRing setProgress:downloadProgress.fractionCompleted animated:YES]; 54 | NSLog(@"%f", downloadProgress.fractionCompleted); 55 | }); 56 | } success:^(BGDownloadRequest * _Nonnull request, NSURL * _Nullable filePath) { 57 | NSLog(@"%@", filePath); 58 | self.progressViewRing.hidden = YES; 59 | [self.webView loadRequest:[NSURLRequest requestWithURL:filePath]]; 60 | } failure:^(BGDownloadRequest * _Nonnull request, NSError * _Nullable error) { 61 | NSLog(@"%@", error); 62 | }]; 63 | self.request = request; 64 | } 65 | 66 | - (IBAction)pauseAction:(id)sender { 67 | [self.request cancelRequest]; 68 | } 69 | 70 | - (void)didReceiveMemoryWarning { 71 | [super didReceiveMemoryWarning]; 72 | // Dispose of any resources that can be recreated. 73 | } 74 | 75 | /* 76 | #pragma mark - Navigation 77 | 78 | // In a storyboard-based application, you will often want to do a little preparation before navigation 79 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 80 | // Get the new view controller using [segue destinationViewController]. 81 | // Pass the selected object to the new view controller. 82 | } 83 | */ 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGUploadViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BGUploadViewController.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/22. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BGUploadViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGUploadViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BGUploadViewController.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/22. 6 | // Copyright © 2015年 BGNetwork https://github.com/liuchungui/BGNetwork/tree/dev. All rights reserved. 7 | // 8 | 9 | #import "BGUploadViewController.h" 10 | #import "AFHTTPSessionManager.h" 11 | #import "BGUploadRequest.h" 12 | 13 | @interface BGUploadViewController () 14 | 15 | @end 16 | 17 | @implementation BGUploadViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view from its nib. 22 | } 23 | 24 | - (void)didReceiveMemoryWarning { 25 | [super didReceiveMemoryWarning]; 26 | // Dispose of any resources that can be recreated. 27 | } 28 | 29 | - (IBAction)uploadAction:(id)sender { 30 | NSString *serverStr = @"upload.php"; 31 | AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"https://casetree.cn/web/test/"]]; 32 | 33 | //请求的serializer 34 | AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer]; 35 | [serializer setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; 36 | manager.requestSerializer = serializer; 37 | 38 | //response的serializer 39 | manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 40 | manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]; 41 | 42 | UIImage *image = [UIImage imageNamed:@"icon_shanchu.png"]; 43 | NSURLSessionDataTask *task = [manager POST:serverStr parameters:@{@"test":@"hello"} constructingBodyWithBlock:^(id _Nonnull formData) { 44 | [formData appendPartWithFileData:UIImageJPEGRepresentation(image, 1.0) name:@"fileUpload" fileName:@"IMG_20150617_105877.jpg" mimeType:@"application/octet-stream"]; 45 | } progress:^(NSProgress * _Nonnull uploadProgress) { 46 | NSLog(@"%f", uploadProgress.fractionCompleted); 47 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { 48 | NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; 49 | NSLog(@"%@", string); 50 | NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; 51 | NSLog(@"%@", resultDic); 52 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { 53 | NSLog(@"%@", error); 54 | }]; 55 | 56 | [task resume]; 57 | } 58 | 59 | - (IBAction)bgUploadAction:(id)sender { 60 | UIImage *image = [UIImage imageNamed:@"icon_shanchu.png"]; 61 | BGUploadRequest *request = [[BGUploadRequest alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; 62 | request.methodName = @"upload.php"; 63 | [request sendRequestWithProgress:^(NSProgress * _Nonnull uploadProgress) { 64 | NSLog(@"%f", uploadProgress.fractionCompleted); 65 | } success:^(BGNetworkRequest * _Nonnull request, id _Nullable response) { 66 | NSLog(@"%@", response); 67 | } businessFailure:^(BGNetworkRequest * _Nonnull request, id _Nullable response) { 68 | NSLog(@"%@", response); 69 | } networkFailure:^(BGNetworkRequest * _Nonnull request, NSError * _Nullable error) { 70 | NSLog(@"%@", error); 71 | }]; 72 | } 73 | 74 | /* 75 | #pragma mark - Navigation 76 | 77 | // In a storyboard-based application, you will often want to do a little preparation before navigation 78 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 79 | // Get the new view controller using [segue destinationViewController]. 80 | // Pass the selected object to the new view controller. 81 | } 82 | */ 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/BGUploadViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 28 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/TableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.h 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/12/7. 6 | // Copyright © 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TableViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/ViewController/Demo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/12. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BaseViewController.h" 10 | 11 | @interface ViewController : BaseViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseCell.h 3 | // I500user 4 | // 5 | // Created by verne on 15/4/8. 6 | // Copyright (c) 2015年 家伟 李. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BaseCell : UITableViewCell 12 | 13 | /** 14 | * 用xib创建Cell 15 | * 16 | * @return self; 17 | */ 18 | + (id)loadFromXib; 19 | 20 | /** 21 | * 用代码创建Cell时候设置的cellIdentifier 22 | * 23 | * @return cellIdentifier; 24 | */ 25 | + (NSString*)cellIdentifier; 26 | 27 | /** 28 | * 用代码创建Cell 29 | * 30 | * @return self; 31 | */ 32 | + (id)loadFromCellStyle:(UITableViewCellStyle)cellStyle; 33 | 34 | /** 35 | * 填充cell的对象 36 | * 子类去实现 37 | */ 38 | - (void)fillCellWithObject:(id)object; 39 | 40 | /** 41 | * 计算cell高度 42 | * 子类去实现 43 | */ 44 | + (CGFloat)rowHeightForObject:(id)object; 45 | 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseCell.m 3 | // I500user 4 | // 5 | // Created by verne on 15/4/8. 6 | // Copyright (c) 2015年 家伟 李. All rights reserved. 7 | // 8 | 9 | #import "BaseCell.h" 10 | 11 | @implementation BaseCell 12 | 13 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 14 | { 15 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 16 | if (self) { 17 | // Initialization code 18 | } 19 | return self; 20 | } 21 | 22 | +(id)loadFromXib 23 | { 24 | return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:self options:nil]lastObject]; 25 | } 26 | 27 | +(NSString*)cellIdentifier 28 | { 29 | return NSStringFromClass(self); 30 | } 31 | 32 | +(id)loadFromCellStyle:(UITableViewCellStyle)cellStyle{ 33 | 34 | return [[self alloc] initWithStyle:cellStyle reuseIdentifier:NSStringFromClass(self)]; 35 | } 36 | 37 | - (void)awakeFromNib 38 | { 39 | // self.contentView.backgroundColor = [UIColor whiteColor]; 40 | // Initialization code 41 | } 42 | 43 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated 44 | { 45 | [super setSelected:selected animated:animated]; 46 | } 47 | 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseCollectionViewCell.h 3 | // TCGroupLeader 4 | // 5 | // Created by vernepung on 15/5/22. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BaseCollectionViewCell : UICollectionViewCell 12 | /** 13 | * 用xib创建Cell 14 | * 15 | * @return self; 16 | */ 17 | +(id)loadFromXib; 18 | 19 | /** 20 | * 用代码创建Cell时候设置的cellIdentifier 21 | * 22 | * @return cellIdentifier; 23 | */ 24 | +(NSString*)cellIdentifier; 25 | 26 | /** 27 | * 填充cell的对象 28 | * 子类去实现 29 | */ 30 | - (void)fillCellWithObject:(id)object; 31 | /** 32 | * 获取size 33 | * 34 | * @param object object description 35 | * 36 | * @return return value description 37 | */ 38 | + (CGSize)sizeForObject:(id)object; 39 | @end 40 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseCollectionViewCell.m 3 | // TCGroupLeader 4 | // 5 | // Created by vernepung on 15/5/22. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseCollectionViewCell.h" 10 | 11 | @implementation BaseCollectionViewCell 12 | 13 | 14 | +(id)loadFromXib 15 | { 16 | return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:self options:nil]lastObject]; 17 | } 18 | 19 | - (void)awakeFromNib 20 | { 21 | self.contentView.backgroundColor = [UIColor whiteColor]; 22 | // Initialization code 23 | } 24 | 25 | +(NSString*)cellIdentifier 26 | { 27 | return NSStringFromClass(self); 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseDoubleLineCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseDoubleLineCell.h 3 | // TCGroupLeader 4 | // 5 | // Created by user on 15/5/20. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseLineCell.h" 10 | 11 | @interface BaseDoubleLineCell : BaseLineCell 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseDoubleLineCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseDoubleLineCell.m 3 | // TCGroupLeader 4 | // 5 | // Created by user on 15/5/20. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseDoubleLineCell.h" 10 | 11 | @implementation BaseDoubleLineCell 12 | - (void)drawRect:(CGRect)rect { 13 | // Drawing code 14 | [super drawRect:rect]; 15 | // Drawing code 16 | //顶部画一条线 17 | CGContextRef context = UIGraphicsGetCurrentContext(); 18 | CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); 19 | CGContextSetLineWidth(context, 0.5); 20 | CGContextMoveToPoint(context, 0, 0); 21 | CGContextAddLineToPoint(context, rect.size.width, 0.25); 22 | CGContextStrokePath(context); 23 | } 24 | @end 25 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseDoubleLineView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseDoubleLineView.h 3 | // TCGroupLeader 4 | // 5 | // Created by user on 15/5/20. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseLineView.h" 10 | 11 | /** 上下都有线的视图 */ 12 | @interface BaseDoubleLineView : BaseLineView 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseDoubleLineView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseDoubleLineView.m 3 | // TCGroupLeader 4 | // 5 | // Created by user on 15/5/20. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseDoubleLineView.h" 10 | 11 | @implementation BaseDoubleLineView 12 | - (void)drawRect:(CGRect)rect { 13 | // Drawing code 14 | [super drawRect:rect]; 15 | // Drawing code 16 | //顶部画一条线 17 | CGContextRef context = UIGraphicsGetCurrentContext(); 18 | CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); 19 | CGContextSetLineWidth(context, BaseLineViewLineWidth); 20 | CGContextMoveToPoint(context, 0, BaseLineViewLineWidth/2.0); 21 | CGContextAddLineToPoint(context, rect.size.width, BaseLineViewLineWidth/2.0); 22 | CGContextStrokePath(context); 23 | } 24 | @end 25 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseLineCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLineCell.h 3 | // I500user 4 | // 5 | // Created by user on 15/4/10. 6 | // Copyright (c) 2015年 家伟 李. All rights reserved. 7 | // 8 | 9 | #import "BaseCell.h" 10 | 11 | /** 底部带线的cell */ 12 | @interface BaseLineCell : BaseCell 13 | /** 下划线的颜色 */ 14 | @property (nonatomic, strong) UIColor *lineColor; 15 | 16 | /** 17 | * 请使用customBackgroundColor代替 18 | */ 19 | @property (nonatomic, strong) UIColor *backgroundColor NS_DEPRECATED_IOS(2_0, 2_1); 20 | 21 | /** 22 | * 设置背景色 23 | */ 24 | @property (nonatomic, strong) UIColor *customBackgroundColor; 25 | 26 | /** 27 | * 线距离左右的空白,默认为0 28 | */ 29 | @property (nonatomic, assign) CGFloat lineMargin; 30 | @end 31 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseLineCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLineCell.m 3 | // I500user 4 | // 5 | // Created by user on 15/4/10. 6 | // Copyright (c) 2015年 家伟 李. All rights reserved. 7 | // 8 | 9 | #import "BaseLineCell.h" 10 | 11 | /** 12 | * 线的宽度 13 | */ 14 | static const CGFloat kLineWidth = 0.5; 15 | @interface BaseLineCell (){ 16 | } 17 | 18 | @end 19 | @implementation BaseLineCell 20 | - (void)awakeFromNib{ 21 | [super awakeFromNib]; 22 | self.customBackgroundColor = [UIColor whiteColor]; 23 | //ios7下,需要将这两个背景色更改成clearColor 24 | self.contentView.backgroundColor = [UIColor clearColor]; 25 | } 26 | 27 | - (void)setCustomBackgroundColor:(UIColor *)customBackgroundColor{ 28 | /** 29 | * 将背景色和contentView背景色改成透明 30 | */ 31 | [super setBackgroundColor:[UIColor clearColor]]; 32 | self.contentView.backgroundColor = [UIColor clearColor]; 33 | _customBackgroundColor = customBackgroundColor; 34 | [self setNeedsDisplay]; 35 | } 36 | 37 | - (UIColor *)backgroundColor{ 38 | return _customBackgroundColor; 39 | } 40 | 41 | - (void)setLineMargin:(CGFloat)lineMargin{ 42 | _lineMargin = lineMargin; 43 | [self setNeedsDisplay]; 44 | } 45 | 46 | // Only override drawRect: if you perform custom drawing. 47 | // An empty implementation adversely affects performance during animation. 48 | - (void)drawRect:(CGRect)rect { 49 | [super drawRect:rect]; 50 | if(!self.lineColor){ 51 | self.lineColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0]; 52 | // self.lineColor = UIColorFromRGB(0xd9d9d9); 53 | } 54 | 55 | /** 56 | * 画背景色,若是没有设置背景色,则默认用白色 57 | */ 58 | UIColor *bgColor = self.customBackgroundColor; 59 | if(bgColor == nil){ 60 | [super setBackgroundColor:[UIColor clearColor]]; 61 | self.contentView.backgroundColor = [UIColor clearColor]; 62 | _customBackgroundColor = [UIColor whiteColor]; 63 | bgColor = [UIColor whiteColor]; 64 | } 65 | 66 | CGContextRef context = UIGraphicsGetCurrentContext(); 67 | CGContextSaveGState(context); 68 | CGContextSetFillColorWithColor(context, bgColor.CGColor); 69 | CGContextAddRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height)); 70 | CGContextDrawPath(context, kCGPathFill); 71 | CGContextRestoreGState(context); 72 | 73 | /** 74 | * 底部画一条线 75 | */ 76 | // CGContextRef context = UIGraphicsGetCurrentContext(); 77 | CGFloat margin = _lineMargin; 78 | CGContextSaveGState(context); 79 | CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); 80 | CGContextSetLineWidth(context, kLineWidth); 81 | CGContextMoveToPoint(context, margin, rect.size.height-kLineWidth/2.0); 82 | CGContextAddLineToPoint(context, rect.size.width-2*margin, rect.size.height-kLineWidth/2.0); 83 | CGContextStrokePath(context); 84 | CGContextRestoreGState(context); 85 | } 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseLineCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseLineView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLineView.h 3 | // TCGroupLeader 4 | // 5 | // Created by user on 15/5/18. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseView.h" 10 | /** 11 | * 线的宽度 12 | */ 13 | UIKIT_EXTERN const CGFloat BaseLineViewLineWidth; 14 | /** 底部有下划线的view */ 15 | @interface BaseLineView : BaseView 16 | /** 17 | * 画线的颜色 18 | */ 19 | @property (nonatomic, strong) UIColor *lineColor; 20 | @end 21 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseLineView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseLineView.m 3 | // TCGroupLeader 4 | // 5 | // Created by user on 15/5/18. 6 | // Copyright (c) 2015年 www.tuanche.com. All rights reserved. 7 | // 8 | 9 | #import "BaseLineView.h" 10 | /** 11 | * 线的宽度 12 | */ 13 | const CGFloat BaseLineViewLineWidth = 0.5; 14 | 15 | @interface BaseLineView (){ 16 | UIColor *_lineBackgroundColor; 17 | } 18 | 19 | @end 20 | @implementation BaseLineView 21 | 22 | - (void)setBackgroundColor:(UIColor *)backgroundColor{ 23 | _lineBackgroundColor = backgroundColor; 24 | [self setNeedsDisplay]; 25 | } 26 | 27 | - (UIColor *)backgroundColor{ 28 | return _lineBackgroundColor; 29 | } 30 | // Only override drawRect: if you perform custom drawing. 31 | // An empty implementation adversely affects performance during animation. 32 | - (void)drawRect:(CGRect)rect { 33 | [super drawRect:rect]; 34 | if(!self.lineColor){ 35 | // self.lineColor = UIColorFromRGB(0xd9d9d9); 36 | self.lineColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0]; 37 | } 38 | /** 39 | * 将背景色和contentView背景色改成透明 40 | */ 41 | [super setBackgroundColor:[UIColor clearColor]]; 42 | 43 | /** 44 | * 画背景色 45 | */ 46 | UIColor *bgColor = _lineBackgroundColor; 47 | if(bgColor){ 48 | CGContextRef context = UIGraphicsGetCurrentContext(); 49 | CGContextSaveGState(context); 50 | CGContextSetFillColorWithColor(context, bgColor.CGColor); 51 | CGContextAddRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height-BaseLineViewLineWidth/2.0)); 52 | CGContextDrawPath(context, kCGPathFill); 53 | CGContextRestoreGState(context); 54 | } 55 | 56 | /** 57 | * 底部画一条线 58 | */ 59 | CGContextRef context = UIGraphicsGetCurrentContext(); 60 | CGContextSaveGState(context); 61 | CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); 62 | CGContextSetLineWidth(context, BaseLineViewLineWidth); 63 | CGContextMoveToPoint(context, 0, rect.size.height-BaseLineViewLineWidth/2.0); 64 | CGContextAddLineToPoint(context, rect.size.width, rect.size.height-BaseLineViewLineWidth/2.0); 65 | CGContextStrokePath(context); 66 | CGContextRestoreGState(context); 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseView.h 3 | // Hands-Seller 4 | // 5 | // Created by guobo on 14-4-18. 6 | // Copyright (c) 2014年 李 家伟. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BaseView : UIView 12 | /** 13 | * @brief 以对应的类名来加载xib文件 14 | * 15 | * @return 返回对应的视图对象 16 | */ 17 | + (id)loadFromXib; 18 | 19 | /** 20 | * @brief 通过object来填充视图 21 | * 22 | * @param object 数据对象 23 | */ 24 | - (void)fillViewWithObject:(id)object; 25 | 26 | 27 | /** 28 | * @brief 通过数据对象来确定当前视图的尺寸和位置 29 | * 30 | * @param object 数据对象 31 | * 32 | * @return 当前视图的frame 33 | */ 34 | - (CGRect)frameForObject:(id)object; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Base/BaseView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BaseView.m 3 | // Hands-Seller 4 | // 5 | // Created by guobo on 14-4-18. 6 | // Copyright (c) 2014年 李 家伟. All rights reserved. 7 | // 8 | 9 | #import "BaseView.h" 10 | 11 | @implementation BaseView 12 | +(id)loadFromXib 13 | { 14 | return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:self options:nil]lastObject]; 15 | } 16 | 17 | - (void)fillViewWithObject:(id)object{ 18 | 19 | } 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Demo/DemoCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoCell.h 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "BaseDoubleLineCell.h" 10 | 11 | @interface DemoCell : BaseDoubleLineCell 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/Demo/DemoCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoCell.m 3 | // DemoNetwork 4 | // 5 | // Created by user on 15/5/13. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import "DemoCell.h" 10 | #import "DemoModel.h" 11 | 12 | @interface DemoCell () 13 | @property (weak, nonatomic) IBOutlet UILabel *nameLabel; 14 | @property (weak, nonatomic) IBOutlet UILabel *sexLabel; 15 | @property (weak, nonatomic) IBOutlet UILabel *ageLabel; 16 | 17 | @end 18 | @implementation DemoCell 19 | 20 | - (void)awakeFromNib{ 21 | [super awakeFromNib]; 22 | // self.lineColor = [UIColor redColor]; 23 | } 24 | /* 25 | // Only override drawRect: if you perform custom drawing. 26 | // An empty implementation adversely affects performance during animation. 27 | - (void)drawRect:(CGRect)rect { 28 | // Drawing code 29 | } 30 | */ 31 | - (void)fillCellWithObject:(id)object{ 32 | DemoModel *model = (DemoModel *)object; 33 | _nameLabel.text = model.name; 34 | _ageLabel.text = [NSString stringWithFormat:@"年龄:%zd", model.age]; 35 | switch (model.sex) { 36 | case 1: 37 | _sexLabel.text = @"男"; 38 | break; 39 | case 2: 40 | _sexLabel.text = @"女"; 41 | break; 42 | case 0: 43 | _sexLabel.text = @"未知"; 44 | break; 45 | } 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/RefreshConstant.h: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshConstant.h 3 | // 4 | // Created by verne on 15/5/8. 5 | // Copyright (c) 2015年 家伟 李. All rights reserved. 6 | // 7 | 8 | 9 | #ifndef PublicProject_RefreshConstant_h 10 | #define PublicProject_RefreshConstant_h 11 | #define TEXT_PULL_UP_TITLE @"下拉刷新" 12 | #define TEXT_PULL_UP_RELEX @"松开即可刷新" 13 | #define TEXT_PULL_LOADING @"加载中..." 14 | 15 | typedef enum{ 16 | /** 17 | * 正在拉动 18 | */ 19 | PullRefreshPulling = 0, 20 | /** 21 | * 已经超出刷新offsetY的临界值 22 | */ 23 | PullRefreshNormal, 24 | /** 25 | * 正在执行动画 26 | */ 27 | PullRefreshLoading, 28 | } PullRefreshState; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/RefreshTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshTableView.h 3 | // 4 | // 在EgoRefresh上进行的简易封装,项目原因直接改名为RefreshTableView 5 | // 6 | // 7 | // 刷新需要用到的图片名称为:(参见Resource下图片 8 | // @"refresh_arrow.png" @"refresh_rotate.png"; 9 | // 10 | // Created by verne on 15/5/8. 11 | // Copyright (c) 2015年 家伟 李. All rights reserved. 12 | // 13 | 14 | #import 15 | #import "RefreshConstant.h" 16 | 17 | @protocol RefreshTableViewDelegate; 18 | /** 19 | * 下拉刷新TableView 20 | * 21 | * 刷新需要用到的图片名称为,使用时需要在项目下加入: 22 | * @"refresh_arrow.png" @"refresh_rotate.png"]; 23 | * 默认为_refresh_arrow.png,_refresh_rotate.png 24 | */ 25 | @interface RefreshTableView : UIView 26 | 27 | @property (weak,nonatomic) id delegate; 28 | 29 | /** 30 | * y到达多少之后开始加载更多 31 | * 默认:200 32 | */ 33 | @property (assign,nonatomic) NSInteger loadMorePostion; 34 | 35 | /** 36 | * 是否没有更多 37 | */ 38 | @property (assign,nonatomic) BOOL isCompleted; 39 | /** 40 | * 加载全部完成后是否移除底部View 41 | */ 42 | @property (assign,nonatomic) BOOL isRemoveFootViewWhenLoadMoreCompleted; 43 | 44 | - (id)initWithFrame:(CGRect)frame withRefreshHeadView:(BOOL)isHeadRefreshViewExsit withRefreshFootView:(BOOL)isFootRefreshViewExsit; 45 | /** 46 | * 获取当前View中的UITableView 47 | * 48 | * @return UITableView 49 | */ 50 | -(UITableView*)getTableView; 51 | /** 52 | * 设置下拉刷新是否存在 53 | * 54 | * @param isExist 55 | */ 56 | -(void)showHeadRefreshView:(BOOL)isExist; 57 | /** 58 | * 设置上拉刷新是否存在 59 | * 60 | * @param isExist 61 | */ 62 | -(void)showFootRefreshView:(BOOL)isExist; 63 | /** 64 | * 刷新UITableView的数据(注:不能直接使用UITableview的reloadData直接去刷新数据) 65 | */ 66 | -(void)reloadData; 67 | 68 | /** 69 | * 重用Cell 70 | * 71 | * @param identifier cell的标志 72 | * 73 | * @return cell 74 | */ 75 | - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; 76 | /** 77 | * 设置分割线 78 | * 79 | * @param style UITableViewCellSeparatorStyle 80 | */ 81 | -(void)setSeperatorLine:(UITableViewCellSeparatorStyle)style; 82 | 83 | -(void)setTableHeadView:(UIView*)headView; 84 | -(void)setTableFootView:(UIView*)footView; 85 | /** 86 | * 手动点击刷新按钮时调用 87 | */ 88 | -(void)refreshData; 89 | /** 90 | * 第一次加载网络请求时调用 91 | */ 92 | -(void)refreshView; 93 | /* 94 | *@note 当数据加载失败时候,使用此方法使下拉界面恢复原状。不必调用reloadData。 95 | */ 96 | -(void)stopPullDownRefresh; 97 | @end 98 | 99 | @protocol RefreshTableViewDelegate 100 | @required 101 | 102 | -(UITableViewCell *)refreshTableView:(RefreshTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 103 | -(CGFloat)refreshTableView:(RefreshTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 104 | -(NSInteger)refreshTableView:(RefreshTableView *)tableView numberOfRowsInSection:(NSInteger)section; 105 | @optional 106 | -(void)refreshTableView:(RefreshTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 107 | -(CGFloat)refreshTableView:(RefreshTableView *)tableView heightForHeaderInSection:(NSInteger)section; 108 | -(UIView*)refreshTableView:(RefreshTableView *)tableView viewForHeaderInSection:(NSInteger)section; 109 | -(CGFloat)refreshTableView:(RefreshTableView *)tableView heightForFooterInSection:(NSInteger)section; 110 | -(UIView*)refreshTableView:(RefreshTableView *)tableView viewForFooterInSection:(NSInteger)section; 111 | -(NSInteger)numberOfSectionsInRefreshTableView:(RefreshTableView *)tableView; 112 | /* 113 | *删除 编辑 114 | */ 115 | - (BOOL)refreshTableView:(RefreshTableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath; 116 | - (UITableViewCellEditingStyle)refreshTableView:(RefreshTableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath; 117 | - (NSString *)refreshTableView:(RefreshTableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath; 118 | - (void)refreshTableView:(RefreshTableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath; 119 | - (void)refreshTableView:(RefreshTableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath; 120 | 121 | -(void)scrollViewDidScroll:(UITableView*)tableView; 122 | -(void)reloadSections:(NSIndexPath*)indexPath; 123 | /** 124 | * 下拉刷新数据代理方法 125 | */ 126 | -(void)pullDownRefreshTableView:(RefreshTableView *)tableView; 127 | /** 128 | * 上拉刷新数据代理方法 129 | */ 130 | -(void)pullUpRefreshTableView:(RefreshTableView *)tableView; 131 | /** 132 | * 手动点击刷新按钮的代理方法 133 | * 134 | */ 135 | -(void)manualRefreshTableView:(RefreshTableView *)tableView; 136 | -(void)autoLoadMoreRefreshTableView:(RefreshTableView *)tableView; 137 | 138 | @end -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/RefreshTimeHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshTimeHelper.h 3 | // 4 | // Created by verne on 15/5/8. 5 | // Copyright (c) 2015年 家伟 李. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface RefreshTimeHelper : NSObject 11 | 12 | +(NSString*)formatTime:(NSDate*)d; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/RefreshTimeHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshTimeHelper.m 3 | // 4 | // Created by verne on 15/5/8. 5 | // Copyright (c) 2015年 家伟 李. All rights reserved. 6 | // 7 | 8 | #import "RefreshTimeHelper.h" 9 | 10 | @implementation RefreshTimeHelper 11 | 12 | +(NSString*)formatTime:(NSDate*)d 13 | { 14 | NSTimeInterval late = [d timeIntervalSince1970]*1; 15 | 16 | NSString * timeString = nil; 17 | 18 | NSDate * dat = [NSDate dateWithTimeIntervalSinceNow:0]; 19 | 20 | NSTimeInterval now = [dat timeIntervalSince1970]*1; 21 | 22 | NSTimeInterval cha = now - late; 23 | if (cha/3600 < 1) { 24 | 25 | timeString = [NSString stringWithFormat:@"%f", cha/60]; 26 | 27 | timeString = [timeString substringToIndex:timeString.length-7]; 28 | 29 | int num= [timeString intValue]; 30 | 31 | if (num <= 1) { 32 | 33 | timeString = [NSString stringWithFormat:@"刚刚..."]; 34 | 35 | }else{ 36 | 37 | timeString = [NSString stringWithFormat:@"%@分钟前", timeString]; 38 | 39 | } 40 | 41 | } 42 | 43 | if (cha/3600 > 1 && cha/86400 < 1) { 44 | 45 | timeString = [NSString stringWithFormat:@"%f", cha/3600]; 46 | 47 | timeString = [timeString substringToIndex:timeString.length-7]; 48 | 49 | timeString = [NSString stringWithFormat:@"%@小时前", timeString]; 50 | 51 | } 52 | 53 | if (cha/86400 > 1) 54 | 55 | { 56 | 57 | timeString = [NSString stringWithFormat:@"%f", cha/86400]; 58 | 59 | timeString = [timeString substringToIndex:timeString.length-7]; 60 | 61 | int num = [timeString intValue]; 62 | 63 | if (num < 2) { 64 | 65 | timeString = [NSString stringWithFormat:@"昨天"]; 66 | 67 | }else if(num == 2){ 68 | 69 | timeString = [NSString stringWithFormat:@"前天"]; 70 | 71 | }else if (num > 2 && num <7){ 72 | 73 | timeString = [NSString stringWithFormat:@"%@天前", timeString]; 74 | 75 | }else if (num >= 7 && num <= 10) { 76 | 77 | timeString = [NSString stringWithFormat:@"1周前"]; 78 | 79 | }else if(num > 10){ 80 | NSDateFormatter* formater = [[NSDateFormatter alloc]init]; 81 | formater.dateFormat = @"yyyy年MM月dd日"; 82 | timeString = [formater stringFromDate:d]; 83 | } 84 | 85 | } 86 | return timeString; 87 | } 88 | @end 89 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/Resource/_refresh_arrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuchungui/BGNetwork/a1345c50735e73d7bf6d9c9627731fe1fcc8bcee/BGNetworkDemo/Views/RefreshTableView/Resource/_refresh_arrow@2x.png -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/Resource/_refresh_rotate@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuchungui/BGNetwork/a1345c50735e73d7bf6d9c9627731fe1fcc8bcee/BGNetworkDemo/Views/RefreshTableView/Resource/_refresh_rotate@2x.png -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/Source/RefreshTableFooterView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshTableFooterView.h 3 | // 4 | // Created by verne on 15/5/8. 5 | // Copyright (c) 2015年 家伟 李. All rights reserved. 6 | // 7 | 8 | #import 9 | typedef enum 10 | { 11 | RefreshTableView_FOOT_VIEW_LOADING=0, 12 | RefreshTableView_FOOT_VIEW_NO_MORE 13 | }RefreshTableView_FOOT_VIEW_STATE; 14 | @interface RefreshTableFooterView : UIView 15 | 16 | -(void)viewLayoutWithStype:(RefreshTableView_FOOT_VIEW_STATE)type; 17 | +(id)loadFromXib; 18 | @end 19 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/Source/RefreshTableFooterView.m: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshTableFooterView.m 3 | // 4 | // Created by verne on 15/5/8. 5 | // Copyright (c) 2015年 家伟 李. All rights reserved. 6 | // 7 | 8 | 9 | #import "RefreshTableFooterView.h" 10 | 11 | 12 | @interface RefreshTableFooterView() 13 | { 14 | int _angle; 15 | BOOL _isStop; 16 | } 17 | @property (weak, nonatomic) IBOutlet UIImageView*activityImageView; 18 | @property (weak, nonatomic) IBOutlet UIButton *loadMoreBtn; 19 | @property (weak, nonatomic) IBOutlet UILabel *statusLabel; 20 | @end 21 | 22 | @implementation RefreshTableFooterView 23 | 24 | -(void)dealloc 25 | { 26 | [_activityImageView.layer removeAllAnimations]; 27 | } 28 | +(id)loadFromXib 29 | { 30 | return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil]lastObject]; 31 | } 32 | -(void)awakeFromNib 33 | { 34 | [super awakeFromNib]; 35 | _angle = 0; 36 | [self viewLayoutWithStype:RefreshTableView_FOOT_VIEW_LOADING]; 37 | [self startAnimation]; 38 | } 39 | 40 | -(void)viewLayoutWithStype:(RefreshTableView_FOOT_VIEW_STATE)type 41 | { 42 | UIImage *rotateImg = [UIImage imageNamed:@"refresh_rotate.png"]; 43 | if(!rotateImg) 44 | { 45 | rotateImg = [UIImage imageNamed:@"_refresh_rotate.png"]; 46 | } 47 | 48 | [_activityImageView setImage:rotateImg]; 49 | float width = self.superview.frame.size.width; 50 | CGRect frame = self.frame; 51 | frame.size.width = width; 52 | self.frame = frame; 53 | if (type==RefreshTableView_FOOT_VIEW_NO_MORE) 54 | { 55 | [self stopAnimating]; 56 | _activityImageView.hidden = YES; 57 | [_statusLabel setText:@"已显示全部"]; 58 | [_statusLabel sizeToFit]; 59 | _statusLabel.center = CGPointMake(self.frame.size.width/2, _statusLabel.center.y); 60 | } 61 | else 62 | { 63 | _activityImageView.hidden = NO; 64 | [_statusLabel setText:@"加载中..."]; 65 | [_statusLabel sizeToFit]; 66 | _statusLabel.center = CGPointMake(self.frame.size.width/2, _statusLabel.center.y); 67 | CGRect activityFrame = _activityImageView.frame; 68 | activityFrame.origin.x = width/2-60; 69 | _activityImageView.frame = activityFrame; 70 | self.alpha = 1; 71 | frame.size.height = 48; 72 | } 73 | self.frame = frame; 74 | } 75 | - (void)startAnimation 76 | { 77 | if (_activityImageView.layer.animationKeys) { 78 | return; 79 | } 80 | CABasicAnimation* rotationAnimation; 81 | rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 82 | rotationAnimation.toValue = [NSNumber numberWithFloat: (-1*M_PI * 2.0) ]; 83 | [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 84 | rotationAnimation.duration = 0.5f; 85 | rotationAnimation.repeatCount = MAXFLOAT;//你可以设置到最大的整数值 86 | rotationAnimation.cumulative = NO; 87 | rotationAnimation.removedOnCompletion = NO; 88 | rotationAnimation.fillMode = kCAFillModeBackwards; 89 | [_activityImageView.layer addAnimation:rotationAnimation forKey:@"Rotation"]; 90 | } 91 | -(void)endAnimation 92 | { 93 | _angle -= 90; 94 | _angle = _angle%360; 95 | } 96 | -(void)stopAnimating 97 | { 98 | // _isStop = YES; 99 | } 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/Source/RefreshTableFooterView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /BGNetworkDemo/Views/RefreshTableView/Source/RefreshTableHeaderView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RefreshTableHeaderView.h 3 | // 4 | // Created by verne on 15/5/8. 5 | // Copyright (c) 2015年 家伟 李. All rights reserved. 6 | // 7 | 8 | 9 | #import 10 | #import 11 | #import "RefreshConstant.h" 12 | #import "RefreshTimeHelper.h" 13 | 14 | 15 | @protocol RefreshTableHeaderDelegate; 16 | @interface RefreshTableHeaderView : UIView { 17 | 18 | __unsafe_unretained id _delegate; 19 | PullRefreshState _state; 20 | /** 21 | * 时间label 22 | */ 23 | UILabel *_lastUpdatedLabel; 24 | /** 25 | * 状态label 26 | */ 27 | UILabel *_statusLabel; 28 | /** 29 | * 箭头图标 30 | */ 31 | CALayer *_arrowImage; 32 | /** 33 | * loading图 34 | */ 35 | UIActivityIndicatorView *_activityView; 36 | /** 37 | * Description 38 | */ 39 | UIImageView *_statusImageView; 40 | 41 | } 42 | 43 | @property(nonatomic,assign) id delegate; 44 | 45 | - (id)initWithFrame:(CGRect)frame textColor:(UIColor *)textColor arrowImageName:(NSString *)arrow rotateImageName:(NSString *)rotate; 46 | 47 | - (void)refreshLastUpdatedDate; 48 | - (void)refreshScrollViewDidScroll:(UIScrollView *)scrollView; 49 | - (void)refreshScrollViewDidEndDragging:(UIScrollView *)scrollView; 50 | - (void)refreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView; 51 | 52 | @end 53 | @protocol RefreshTableHeaderDelegate 54 | - (void)refreshTableHeaderDidTriggerRefresh:(RefreshTableHeaderView*)view; 55 | - (BOOL)refreshTableHeaderDataSourceIsLoading:(RefreshTableHeaderView*)view; 56 | @optional 57 | - (NSDate*)refreshTableHeaderDataSourceLastUpdated:(RefreshTableHeaderView*)view; 58 | @end 59 | -------------------------------------------------------------------------------- /BGNetworkDemo/casetree.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuchungui/BGNetwork/a1345c50735e73d7bf6d9c9627731fe1fcc8bcee/BGNetworkDemo/casetree.cer -------------------------------------------------------------------------------- /BGNetworkDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BGNetworkDemo 4 | // 5 | // Created by user on 15/9/4. 6 | // Copyright (c) 2015年 lcg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BGNetworkDemo/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDpDCCAowCCQDSPXxGJQVzgzANBgkqhkiG9w0BAQUFADCBkzELMAkGA1UEBhMC 3 | Q04xEDAOBgNVBAgTB0JlaUppbmcxEDAOBgNVBAcTB2JlaWppbmcxEzARBgNVBAoT 4 | CmxpdWNodW5ndWkxEzARBgNVBAsTCmxpdWNodW5ndWkxFTATBgNVBAMTDDE3Mi4x 5 | Ni40LjExNTEfMB0GCSqGSIb3DQEJARYQNDA0NDY4NDk0QHFxLmNvbTAeFw0xNTA5 6 | MjEwNDAzNDNaFw0xNjA5MjAwNDAzNDNaMIGTMQswCQYDVQQGEwJDTjEQMA4GA1UE 7 | CBMHQmVpSmluZzEQMA4GA1UEBxMHYmVpamluZzETMBEGA1UEChMKbGl1Y2h1bmd1 8 | aTETMBEGA1UECxMKbGl1Y2h1bmd1aTEVMBMGA1UEAxMMMTcyLjE2LjQuMTE1MR8w 9 | HQYJKoZIhvcNAQkBFhA0MDQ0Njg0OTRAcXEuY29tMIIBIjANBgkqhkiG9w0BAQEF 10 | AAOCAQ8AMIIBCgKCAQEAz6drPU7BVlda2CfL8/rbwuVlEGK3hAphVJVBWBx3Ucqt 11 | AREuVQzE1BAUzniDCK5WqKDd03WboVcosrJdreV/rYYwaeNDcNlNoNAnsYyCA0yE 12 | lZQuGzJ0pf+VXNB4AwYfVZKGmLhXFoXCVkCJsRcXogoNVsSz765keQ+b2MIMUWV6 13 | qf2zsC5tfe7UOvPQ1cOKV7hg8bEcRKJER9Qc7xYMSy+XwxCWqYoIHRlg7537iGTa 14 | s4ZMud3gRKiAzE0y+Z7QFJTl1jwYy1YibqlyqmC90gsnrPse5uGq5XkZ8jghiHLl 15 | PxmcoR3DNonXMNzWJ9u+TmmJVAXLHqTAGKzvNIWtwwIDAQABMA0GCSqGSIb3DQEB 16 | BQUAA4IBAQBJLVcxXoGMdISwBm1p0i12OoGAezw8eCp3Fc6K/VnwfyOwXVRL+JoF 17 | 82GlGDOSX+xlz/7jr0WpHqJCe25qorTaNMPuHHcPNhDs61DI7QegwqLTKW7D0Lxc 18 | aseXqtR2OLAByhGiZbcqBt73KMGmnWg7HlN0PbbtEKBd9gshOWMjQFSq0z9rEeME 19 | 3Eb+rYofUntzu4gjAZgopULu225NgAPj4le0TFdVsYtfKZXqmeXM9ay3hApw50kR 20 | g5ZiVGLbEQQJd1+AVRiN0cZFLUti8Lwy2prKPuB1OVBLjKSxv4x87Z++1vjfU/Mr 21 | G8YL6ngmNnVMBDW0ITsDzChAhFg4yxBf 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /BGNetworkDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | lcg.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 chunguiLiu 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 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/liuchungui/BGNetwork.svg?branch=dev)](https://travis-ci.org/liuchungui/BGNetwork) 2 | [![codecov.io](https://codecov.io/github/liuchungui/BGNetwork/coverage.svg?branch=dev)](https://codecov.io/github/liuchungui/BGNetwork?branch=dev) 3 | 4 | ##BGNetwork是什么? 5 | BGNetwork是一个基于**AFNetworking**封装的一个网络框架,它主要由**BGNetworkManager**、**BGNetworkRequest**、**BGNetworkConfiguration**、**BGNetworkCache**组成。它的工作流程是先将每个网络请求封装成一个Request对象,然后交给BGNetworkManager发送请求,最后使用block调用回来。 6 | 7 | ##有哪些功能? 8 | * 支持统一设置baseURL 9 | * 提供对url的queryString部分进行配置 10 | * 提供对HTTP请求头的配置 11 | * 提供对HTTP请求体的配置,并可进行加密 12 | * 支持对网络请求的数据进行缓存以及配置不同的缓存策略 13 | * 提供对Response解密的配置 14 | * 扩展了批量发送请求和串行发送请求 15 | * 提供成功、业务失败、网络失败三种block回调 16 | 17 | ##类的介绍 18 | ####BGNetworkRequest 19 | 网络请求类,当发起一个网络请求的时候,需要子类化这个类。BGNetworkRequest提供了跟业务相关的设置,例如设置是GET请求还是POST请求、请求的方法名、请求的业务参数、缓存策略、请求头等等。当需要发起一个请求时,使用sendRequestWithSuccess:businessFailure:networkFailure:发起请求,使用cancelRequest类方法取消请求。 20 | 21 | ####BGNetworkConfiguration 22 | 这是一个整个网络的配置类,它提供的功能有: 23 | 24 | * 配置baseURL 25 | * 对BGNetworkRequest进行预处理 26 | * 对请求统一设置请求头 27 | * 对请求设置query string 28 | * 组装POST请求的请求体 29 | * 对Response进行解密 30 | * 配置对某个请求是否缓存 31 | * 配置当前的请求是业务成功,减少业务层的判断 32 | 33 | 34 | ####BGNetworkManager 35 | 它是一个单例,协调着BGRequest、BGNetworkCache和BGNetworkConfiguration三者进行工作。 36 | 37 | ####BGNetworkCache 38 | 一个以写文件的形式进行缓存的类。 39 | 40 | 41 | ##如何使用? 42 | 43 | 首先,子类化一个BGNetworkConfiguration类,实现BGNetworkConfiguration协议,对网络进行配置,在Appdelegate.m文件中将它设置给BGNetworkManager。 44 | ```objective-c 45 | [[BGNetworkManager sharedManager] setNetworkConfiguration:[DemoNetworkConfiguration configuration]]; 46 | ``` 47 | 48 | 其次,根据业务子类化BGNetowrkRequest封装请求,然后发送请求。 49 | 50 | ```objective-c 51 | DemoRequest *request = [[DemoRequest alloc] initPage:_page pageSize:_pageSize]; 52 | [request sendRequestWithSuccess:^(BGNetworkRequest *request, id response) { 53 | [self request:request successWithResponse:response]; 54 | } businessFailure:^(BGNetworkRequest *request, id response) { 55 | [self request:request businessFailureWithResponse:response]; 56 | } networkFailure:^(BGNetworkRequest *request, NSError *error) { 57 | [self request:request failureWithNetworkError:error]; 58 | }]; 59 | ``` 60 | 61 | ##Podfile 62 | ``` 63 | platform :ios, '7.0' 64 | pod "BGNetwork" 65 | ``` 66 | 67 | 68 | ##相关类的任务角色 69 |

70 | BGNetwork 71 |

72 | -------------------------------------------------------------------------------- /assets/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuchungui/BGNetwork/a1345c50735e73d7bf6d9c9627731fe1fcc8bcee/assets/architecture.png --------------------------------------------------------------------------------