Search code examples
ioscocoapodsafnetworking

AFNetworking doesn't build with cocoapods on xcode8


I'm on cocoapods 1.1.1, and trying to install this file with pod install:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target "Pictabite" do
    pod 'AFNetworking', '~> 3.1'
    pod 'SDWebImage', '~>3.8'
    pod 'LLSimpleCamera', '~> 5.0'
end

However the project doesn't build after I add AFNetworking. I'm getting this error on Xcode:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_AFNetworkReachabilityManager", referenced from:
      objc-class-ref in AppDelegate.o
      objc-class-ref in UIDevice+Category.o
  "_OBJC_CLASS_$_AFNetworkActivityIndicatorManager", referenced from:
      objc-class-ref in PBHttpSessionManager.o
  "_OBJC_CLASS_$_AFHTTPSessionManager", referenced from:
      _OBJC_CLASS_$_PBHttpSessionManager in PBHttpSessionManager.o
      _OBJC_CLASS_$_PBHttpFQSessionManager in PBHttpFQSessionManager.o
  "_OBJC_METACLASS_$_AFHTTPSessionManager", referenced from:
      _OBJC_METACLASS_$_PBHttpSessionManager in PBHttpSessionManager.o
      _OBJC_METACLASS_$_PBHttpFQSessionManager in PBHttpFQSessionManager.o
  "_OBJC_CLASS_$_AFJSONResponseSerializer", referenced from:
      objc-class-ref in PBHttpSessionManager.o
      objc-class-ref in PBHttpFQSessionManager.o
  "_OBJC_CLASS_$_AFHTTPRequestSerializer", referenced from:
      objc-class-ref in PBHttpSessionManager.o
      objc-class-ref in PBHttpFQSessionManager.o
  "_OBJC_CLASS_$_AFSecurityPolicy", referenced from:
      objc-class-ref in PBHttpSessionManager.o
ld: symbol(s) not found for architecture x86_64
clang-real: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas?


Solution

  • Not specifying cocoapods versions, and using use_frameworks! yields:

    Installing AFNetworking (3.0.4)
    Installing LLSimpleCamera (4.2.0)
    Installing SDWebImage (3.7.5)

    • pod --version: 1.1.1
    • xcodebuild -version: Xcode 8.2.1, Build version 8C1002

    Your Podfile could look like this:

    platform :ios, '10.0'
    
    target 'Pictabite' do
        use_frameworks!
    
        pod 'AFNetworking'
        pod 'SDWebImage'
        pod 'LLSimpleCamera'
    end
    

    Swift 3 Compilation example

    import AFNetworking
    ...
    let configuration = URLSessionConfiguration.default
    let manager = AFURLSessionManager(sessionConfiguration: configuration)
    

    Objective-C Compilation example

    #import "AFNetworking.h"
    ...
    NSURLSessionConfiguration *configuration =
       [NSURLSessionConfiguration defaultSessionConfiguration];
    AFURLSessionManager *manager =
       [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];