在没有pod的情况下导入AFNetworking

aak*_*pro 3 iphone objective-c ios afnetworking

我想在没有pod和源代码的情况下将AFNetworking添加到我的项目中.我首先添加源代码然后添加库.

进口图书馆

然后我添加了前缀文件

#import <Availability.h>

#if __IPHONE_OS_VERSION_MIN_REQUIRED
#ifndef __IPHONE_6_0
#warning "This project uses features only available in iPhone SDK 6.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <SystemConfiguration/SystemConfiguration.h>
    #import <MobileCoreServices/MobileCoreServices.h>
#endif
#else
#ifdef __OBJC__
    #import <Cocoa/Cocoa.h>
    #import <SystemConfiguration/SystemConfiguration.h>
    #import <AssertMacros.h>
    #import <CoreServices/CoreServices.h>
#endif
#endif
Run Code Online (Sandbox Code Playgroud)

并将前缀文件添加到Build Settings - > Apple LLVM 6.1 - Language - > Prefix Header.

之后,我建立了项目,我得到以下错误:

  • 函数'SecItemExport'的隐式声明在C99中无效
  • 使用未声明的标识符'kSecFormatUnknown'使用未声明的标识符
  • 标识符'kSecItemPemArmour'

这些都在文件和行中.AFSecurity Policy.m,第31行.这是:

__Require_noErr_Quiet(SecItemExport(key, kSecFormatUnknown, kSecItemPemArmour, NULL, &data), _out);
Run Code Online (Sandbox Code Playgroud)

当我评论这行不正确的代码时,项目的其余部分是完全构建的.

我该怎么做以及为什么会发生这些错误?

aak*_*pro 7

我在github上找到了答案.

如2.6的发行说明中所述,如果您手动安装库,则需要在项目的pch中定义以下变量:

#ifndef TARGET_OS_IOS
  #define TARGET_OS_IOS TARGET_OS_IPHONE
#endif
#ifndef TARGET_OS_WATCH
  #define TARGET_OS_WATCH 0
#endif
Run Code Online (Sandbox Code Playgroud)

Github Link.


Var*_*ria 7

我的解决方案是在预处理器宏 - 构建设置中添加"TARGET_OS_IOS = 1"