AFNetworking 2.0 出现Use of undeclared identifier AFURLSessionManager错误
当向下面使用时会出现错误
#import "AFNetworking.h"
#import "AFURLSessionManager.h" AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
主要原因是NSURLSession模块仅支持ios7,打开AFURLSessionManager.h会看到一个宏
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
AFURLSessionManager只支持ios7和macosx10.9.0故创建下载任务时
-(void)download:(NSString *)url complete:(void(^)(id result,NSError *error))success{
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryPath = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
return [documentsDirectoryPath URLByAppendingPathComponent:[targetPath lastPathComponent]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
if (error) {
success(nil,error);
}else{
success(filePath,nil);
}
}];
[downloadTask resume];
#else
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:] stringByAppendingPathComponent:[url lastPathComponent]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
success(path,nil);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
success(nil,error);
}];
[operation start];
#endif
}
AFNetworking 2.0 出现Use of undeclared identifier AFURLSessionManager错误的更多相关文章
- Visual Studio 2010 error C2065: '_In_opt_z_' : undeclared identifier 编译错误
当用Visual Studio 2010 编译时 发生如下编译错误: 2>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\inclu ...
- error C2065: 'assert' : undeclared identifier
F:\VC6.0 : error C2065: 'assert' : undeclared identifier 导入#include <assert.h>
- 使用某些Widows API时,明明包含了该头文件,却报错“error C2065: undeclared identifier”
在使用一些新版本的API,或者控件的新特性(比如新版的ComCtl32.dll)的时候,你可能会得到“error C2065: undeclared identifier.“这个错误.原因是这些功能是 ...
- [翻译] Working with NSURLSession: AFNetworking 2.0
Working with NSURLSession: AFNetworking 2.0 简单翻译,有很多错误,看官无法理解处请英文原文对照. http://code.tutsplus.com/tu ...
- [转]AFNetworking 3.0迁移指南
http://www.jianshu.com/p/047463a7ce9b?utm_campaign=hugo&utm_medium=reader_share&utm_content= ...
- error C2065: 'CArchiveStream' : undeclared identifier
release:模式下 问题: 在导入JPEG文件时要使用到 CArchiveStream类 但是编译的时候会出现 'CArchiveStream' : undeclared ide ...
- AFNetworking 3.0 源码解读 总结(干货)(下)
承接上一篇AFNetworking 3.0 源码解读 总结(干货)(上) 21.网络服务类型NSURLRequestNetworkServiceType 示例代码: typedef NS_ENUM(N ...
- AFNetworking 3.0 源码解读(八)之 AFImageDownloader
AFImageDownloader 这个类对写DownloadManager有很大的借鉴意义.在平时的开发中,当我们使用UIImageView加载一个网络上的图片时,其原理就是把图片下载下来,然后再赋 ...
- AFNetworking 3.0 源码解读(七)之 AFAutoPurgingImageCache
这篇我们就要介绍AFAutoPurgingImageCache这个类了.这个类给了我们临时管理图片内存的能力. 前言 假如说我们要写一个通用的网络框架,除了必备的请求数据的方法外,必须提供一个下载器来 ...
随机推荐
- DOM - 5.事件冒泡 + 6.事件中的this
5.事件冒泡 如果元素A嵌套在元素B中,那么A被点击不仅A的onclick事件会被触发,B的onclick也会被触发.触发的顺序是"由内而外" .验证:在页面上添加一个table. ...
- Sublime Text + CTags + Cscope (部分替代Source Insight)
CTags & cscope 下载: CTags+Cscope --- 我的百度云盘下载http://pan.baidu.com/s/1gfyPnuN ctags58.zip --- src ...
- 【翻译十二】java-并发之活性
A concurrent application's ability to execute in a timely manner is known as its liveness. This sect ...
- 吐个槽,对VB6.0 还有VBS 说ByeBye
往事不堪回首,折腾了个把月的老系统,心中郁结,不吐不快.系统架构是ASP +VBS +VB6.0 + SQL Server2000, 第一个版本开发完成大概是在2000年.基本是处于交接无力,看代码就 ...
- POJ 1061 同余方程
两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是 它们出发之前忘记了一件很重要的事情,既没有问清楚对方的 ...
- ios程序播放音频文件
1.控制器代码 #import "ViewController.h" #import <AVFoundation/AVFoundation.h> #import &qu ...
- cocoaPads 安装及出现Analyzing dependencies之后卡死解决方案
1.安装 a. 查看源 gem sources -l b. 设置源: sudo gem sources -a http://ruby.taobao.org c. 删除源:sudo gem source ...
- Fragment实现兼容手机和平板
Android手机的设置界面,点击一下Sound,可以跳转到声音设置界面,如下面两张图所示: 然后再来看一下Android Pad的设置界面,主设置页面和声音设置页面都是在一个 ...
- currentStyle
用js的style属性可以获得html标签的样式,但是不能获取非行间样式. 解决方法: 在IE下可以用currentStyle; 在FF下用getComputedStyle; 然而,为了让其兼容,解决 ...
- mysql 怎样清空一个数据库中的所有表
转自:http://blog.csdn.net/zhangzhizhen1988/article/details/8432146 MySQL清空表是很重要的操作,也是最常见的操作之一,下面就为您详细介 ...