DevStore首页 > DEV资源 > 源码下载 > 源码详情

使用AFNetworking框架管理进行网络请求

 
lingling_7 | 2014-08-18 18:25    浏览量(2955)    评论(1)    收藏(4)
功能分类:其他 支持平台:iOS 运行环境:iOS
开发语言:Object-c 开发工具:Xcode 源码大小:247.33KB
下载源码 225 人下载

源码简介

用AFNetworking管理网络请求,包括发送数据和接收数据。

源码截图

  • AFNetworking框架源码压缩包包含文件
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

- (NSURL *)avatarImageURL {
return [NSURLURLWithString:self.avatarImageURLString];
}

#pragma mark -

#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED

+ (NSOperationQueue *)sharedProfileImageRequestOperationQueue {
static NSOperationQueue *_sharedProfileImageRequestOperationQueue = nil;
static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedProfileImageRequestOperationQueue = [[NSOperationQueue alloc] init];
        [_sharedProfileImageRequestOperationQueue setMaxConcurrentOperationCount:8];
    });

return _sharedProfileImageRequestOperationQueue;
}

- (NSImage *)profileImage {
	if (!_profileImage && !_avatarImageRequestOperation) {
        NSMutableURLRequest *mutableRequest = [NSMutableURLRequest requestWithURL:self.avatarImageURL];
        [mutableRequest setValue:@"image/*" forHTTPHeaderField:@"Accept"];
        AFHTTPRequestOperation *imageRequestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:mutableRequest];
        imageRequestOperation.responseSerializer = [AFImageResponseSerializer serializer];
        [imageRequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, NSImage *responseImage) {
self.profileImage = responseImage;

			_avatarImageRequestOperation = nil;

            [[NSNotificationCenter defaultCenter] postNotificationName:kUserProfileImageDidLoadNotification object:self userInfo:nil];
        } failure:nil];

		[imageRequestOperation setCacheResponseBlock:^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) {
			return [[NSCachedURLResponse alloc] initWithResponse:cachedResponse.response data:cachedResponse.data userInfo:cachedResponse.userInfo storagePolicy:NSURLCacheStorageAllowed];
		}];

		_avatarImageRequestOperation = imageRequestOperation;
		
        [[[self class] sharedProfileImageRequestOperationQueue] addOperation:_avatarImageRequestOperation];
	}
	
	return _profileImage;
}
  •   赞(0) 赞 +1 赞(0) 已赞
  •   收藏(4) 收藏 +1 已收藏 取消
  •   下载(225)
评论(1)
sai

sai 2014-10-17 09:21:38

求积分啊,大神
回复(0) 赞(0) 赞(1)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 12 能力值
  • 6 源码
  • 0 评测
  • 0 资料

热门源码