Giter VIP home page Giter VIP logo

afnetworkingext's Introduction

@DEPRECATED 使用 https://github.com/junhaiyang/AFNetworkingTask

初始目的:

不要过多的关心网络协议底层
简化图片批量下载、下载取消操作,允许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;

afnetworkingext's People

Contributors

goodjok avatar junhaiyang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.