AFNetworking 概述

NSURLSession设计

  1. NSURLSession
  2. NSURLSessionTask
  3. NSURLSessionConfiguration
  4. 代理方法
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; // #1
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration
                                                      delegate:self
                                                 delegateQueue:[NSOperationQueue mainQueue]]; // #2
NSURLSessionDataTask *task = [session dataTaskWithURL:[[NSURL alloc]initWithString:@""]]; // #3
[task resume];
1.Configuration
defaultSessionConfiguration 默认
ephemeralSessionConfiguration 私密的
backgroundSessionConfigurationWithIdentifier
timeoutIntervalForRequest
2.Delegate DelegateQueue
3. Session
4. Task

NSURLSessionTask:超类
NSURLSessionDataTask:请求
NSURLSessionUploadTask:上传(父类是NSURLSessionDataTask
NSURLSessionDownloadTask:下载

Configuration进行配置
Session将Configuration Delegate DelegateQueue 进行关联 返回task
Task是任务类 启动暂停等方法

AFNetworking的设计

总结

static NSString * const
static inline void函数
static NSString * AFCreateMultipartFormBoundary()

[[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingTaskDidCompleteNotification object:task userInfo:userInfo];

代码注释

枚举类型

/**
 Whether or not the network is currently reachable.
 */
@property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;

// setter
self.reachable = YES;
// getter
if (self.isReachable) {}

pragma mark -

.h文件
FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityDidChangeNotification;
FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityNotificationStatusItem;
.m
NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";

你可能感兴趣的:(AFNetworking 概述)