Latest 1.2.1
Homepage https://github.com/junhaiyang/AFNetworkingExt
License MIT
Platforms ios 6.0, requires ARC
Dependencies AFNetworking, AFNetworkActivityLogger, AFgzipRequestSerializer, AFOnoResponseSerializer, Godzippa
Authors

All Code Will @[email protected]

初始目的:

不要过多的关心网络协议底层
简化图片批量下载、下载取消操作,允许UIImageView复用下载不同网络图片
不需要再为同一页面出现相同图片地址下载做任何处理,优化图片渲染效率
强化图片缓存方案

Podfile
如果无法编译,指定下面依赖版本

pod 'AFNetworking', '2.5.3'
pod 'AFNetworkActivityLogger', '2.0.4'
pod 'AFOnoResponseSerializer', '1.0.0'
pod 'AFgzipRequestSerializer', '0.0.2'
pod 'Ono', '1.2.1'
pod 'Godzippa', '1.1.0'

创建

#import "AFNetworkingBaseRequest.h"
@interface TestRequest : AFNetworkingBaseRequest

@end

@implementation TestRequest

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.responseType =ResponseProtocolTypeFile; //文件下载
        self.responseType =ResponseProtocolTypeJSON; //返回JSON
        self.responseType =ResponseProtocolTypeNormal; //返回普通文本

        self.requestType =RequestProtocolTypeNormal; //默认请求
        self.requestType =RequestProtocolTypeJSON; //JSON body 请求 

    }
    return self;
}

-(void)prepareRequest{

    NSString *url = [PROTOCOL_URL stringByAppendingString:POST_FILE_URL];
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    [dictionary setObject:@"121212123123" forKey:@"account"];
    [dictionary setObject:@"111111" forKey:@"passwd"];
    [self buildGetRequest:url form:dictionary];

}

//对应 self.responseType =ResponseProtocolTypeNormal;
-(void)processString:(NSString *)str{
    NSLog(@"processString:%@", str);

}

//对应 self.responseType =ResponseProtocolTypeJSON;
-(void)processDictionary:(id)dictionary{
    NSLog(@"processDictionary:%@", dictionary);
}

//对应 self.responseType =ResponseProtocolTypeFile;
-(void)processFile:(NSString *)filePath{

    NSLog(@"processFile:%@", filePath);
}

@end

使用

TestRequest  *request = [[TestRequest alloc] init]; 
[request uploadBlock:^(NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {

}];

[request downloadBlock:^(NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {

}];

[request finishedBlock:^(AFNetworkingBaseRequest *request, StatusCode errorCode, NSInteger httpStatusCode) {
NSLog(@"-----------completionBlock");
}];

[request executeAsync:queueId];

监控日志

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[AFNetworkActivityLogger sharedLogger] startLogging];
    [[AFNetworkActivityLogger sharedLogger] setLevel:AFLoggerLevelDebug];

    //网络状态
    [AFNetworkActivityIndicatorManager sharedManager];

    ...
}

UIImageView+DYLoading:缓存图片到本地文件系统,并且出现相同下载地址时会自动忽略并在原来请求成功后绘制所有相同图片地址的view

使用network

self.imageView.defaultLoadingImage = [UIImage imageNamed:@"icon"]; 
//imageView.loadingImagePathType = @"icon"; 
//imageView.loadingImagePathKey = [NSString stringWithFormat:@"%lld", user.uid]; 
imageView.loadingQueueId = queueId;

[imageView loadingAsyncImage:imagePath];
//[imageView loadingSyncImage:imagePath];

local

self.imageView.defaultLoadingImage = [UIImage imageNamed:@"icon"]; 
imageView.loadingResourcePath = recourcePath;
[imageView loadingSyncLocalImage];
//[imageView loadingAsyncLocalImage];

cacle loading

[self.imageView recycleLoading];

local chache path: …..APP CACHE DIR/$loadingImagePathType/$loadingImagePathKey/$urlencoding.png

+(NSString *)parseImagePath:(NSString *)imagePathType imageKey:(NSString *)imageKey url:(NSURL *)url;

clear local cache path

+(void)clearImageCache:(NSString *)imagePathType imageKey:(NSString *)imageKey;

Latest podspec

{
    "name": "AFNetworking+Ext",
    "version": "1.2.1",
    "summary": "AFNetworkingu7684u5c01u88c5, u5e76u63d0u4f9bu4e00u4e2a UIImageView+DYLoading  cache in fileSystem+memory",
    "homepage": "https://github.com/junhaiyang/AFNetworkingExt",
    "license": "MIT",
    "authors": {
        "yangjunhai": "[email protected]"
    },
    "platforms": {
        "ios": "6.0"
    },
    "ios": {
        "frameworks": "UIKit"
    },
    "source": {
        "git": "https://github.com/junhaiyang/AFNetworkingExt.git",
        "tag": "1.2.1"
    },
    "requires_arc": true,
    "dependencies": {
        "AFNetworking": [],
        "AFNetworkActivityLogger": [],
        "AFgzipRequestSerializer": [],
        "AFOnoResponseSerializer": [],
        "Godzippa": []
    },
    "subspecs": [
        {
            "name": "Base",
            "source_files": "Ext/*.{h,m,mm}",
            "dependencies": {
                "AFNetworking+Ext/AFCustomRequestOperation": [],
                "AFNetworking+Ext/AFDownloadRequestOperation": [],
                "AFNetworking+Ext/AFTextResponseSerializer": []
            }
        },
        {
            "name": "AFCustomRequestOperation",
            "source_files": "AFCustomRequestOperation/*.{h,m,mm}"
        },
        {
            "name": "AFDownloadRequestOperation",
            "dependencies": {
                "AFNetworking+Ext/AFCustomRequestOperation": []
            },
            "source_files": "AFDownloadRequestOperation/*.{h,m,mm}"
        },
        {
            "name": "AFTextResponseSerializer",
            "source_files": "AFTextResponseSerializer/*.{h,m,mm}"
        },
        {
            "name": "example",
            "dependencies": {
                "AFNetworking+Ext/Base": []
            },
            "source_files": "*.{h,m,mm}"
        },
        {
            "name": "UIKit",
            "subspecs": [
                {
                    "name": "UIImageView+DYLoading",
                    "dependencies": {
                        "AFNetworking+Ext/AFDownloadRequestOperation": [],
                        "AFNetworking+Ext/Base": []
                    },
                    "source_files": "UIKit/UIImageView+DYLoading/*.{h,m,mm}"
                }
            ]
        }
    ]
}

Pin It on Pinterest

Share This