AFNetworking包含标题 [英] AFNetworking include headers

查看:132
本文介绍了AFNetworking包含标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从ASIHttpRequest转换为AFNetworking,但是在我的类的下一行中似乎出现使用未声明的标识符AFURLSessionManager错误。

I'm trying to convert from ASIHttpRequest to AFNetworking but I seem to be having a "Use of undeclared identifier AFURLSessionManager" error on the following line in my class.

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

我在标头中添加了以下内容:

I have included the following on my header:

#import "AFNetworking.h"
#import "AFURLSessionManager.h"

一定很明显,但是现在脑子里放屁了。

It must be something really obvious, but having a bad brain fart right now.

推荐答案

通过 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 使用 NSURLSession ,可从iOS 7(和OSX 10.9)开始使用。

AFURLSessionManager makes use of NSURLSession, which is available from iOS 7 (and OSX 10.9) on.

如果您以iOS 6为目标,则 AFURLSessionManager 不能使用,并且会在编译时删除。这就是为什么会出现错误。

If you are targeting iOS 6, AFURLSessionManager just can't be used and it's stripped out at compile time. That's why you get the error.

将iOS 7设置为最低部署目标将解决编译错误,即使它可能无法满足您的需求。

Setting iOS 7 as minimum deployment target will fix the compile error, even though it may not fit your needs.

我的建议是使用CocoaPods来管理第三方依赖项,例如 AFNetworking

That said, my suggestions is to use CocoaPods to managed third-party dependencies, such as AFNetworking.

AFNetworking 2.0 是一个模块化框架,这意味着您可以根据自己的需要选择要使用的模块需要。该内核支持iOS 6,但是某些模块仅支持iOS 7,例如 NSURLSession 模块,其中 AFURLSessionManager 属于。

AFNetworking 2.0 is a modular framework, meaning that you can pick which modules to use according to your needs. The core supports iOS 6, but some modules only support iOS 7, such as the NSURLSession module which is the one where AFURLSessionManager belongs.

通过使用 CocoaPods子规格。为了导入 AFNetworking NSURLSession 模块,您只需要执行

Modularity is achieved by using CocoaPods subspecs. In order to import AFNetworking and the NSURLSession module, you will just have to do something like

platform :ios, '7.0'

pod 'AFNetworking',              '~> 2.0'
pod 'AFNetworking/NSURLSession', '~> 2.0'

您仍然可以将iOS 6作为目标,但不会得到不兼容的子模块

You still can target iOS 6, but you won't get the incompatible submodules, as specified in the CocoaPods documentation.


子规范可以限制父规范的平台。在这种情况下,只有Podfile的目标支持它时,父规范才会继承它。

A subspec can restrict the platform of the parent specification. In this case it will be inherited by the parent specification only if the target of the podfile supports it.

这篇关于AFNetworking包含标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆