3

I am struggling to make AFNetworking to work on my Today Extension.

My app is an Objective-c project with cocoapods (0.39.0), in which I started to migrate some stuff to Swift. I successfully made Swift to work with objective-c and I am using AFNetworking in both Swift and Objective-c code.

I added a Today Extension (made in Swift) and when I try to use Swift classes that use AFNetworking, it complains that no "AFHTTPRequestOperationManager" and other AFNetworking related classes couldn't be found.

I tried different solutions to the Podfile, which currently is configured like this:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

def testing_pods
    pod 'Google/Analytics', '~> 1.0.0'
    pod 'AFNetworking', '~> 2.6'
    pod 'XCDYouTubeKit', '~> 2.4.0'
    pod 'FBSDKCoreKit'
    pod 'FBSDKShareKit'
    pod 'FBSDKLoginKit'
    pod 'Parse'
    pod 'ParseUI'
    pod 'ParseFacebookUtilsV4'
    pod 'ParseTwitterUtils'
end

target '***' do

    testing_pods

end

target '***' do

    testing_pods

end

target 'todayExtension' do
    pod 'AFNetworking', '~> 2.6'
end

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        puts "=== #{target.name}"
        if target.name == "AFNetworking"
            puts "Setting AFNetworking Macro AF_APP_EXTENSIONS so that it doesn't use UIApplication in extension."
            target.build_configurations.each do |config|
                puts "Setting AF_APP_EXTENSIONS macro in config: #{config}"
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS']
            end
        end
        target.build_configurations.each do |config|
            puts "Setting only_active_arch in config: #{config}"
            config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
        end
    end
end

I already deleted all pods and workspace and created them again but the problem still the same.

Any suggestion?

Thanks

estemendoza
  • 3,023
  • 5
  • 31
  • 51
  • First of all clean build and try to make new bridging-header.h file – imjaydeep Jan 08 '16 at 10:13
  • @imjaydeep Thanks but what does it have to do with it? I forgot to mention that the extension is a Swift extension, not objetive-c, I will include it on the main post. – estemendoza Jan 08 '16 at 10:21
  • this link help you to create header file http://stackoverflow.com/questions/34627082/how-to-find-path-of-bridging-header-h-swift-xcode – imjaydeep Jan 08 '16 at 10:28
  • if you want to get json response through AFnetworking last answer of this link will be helpful http://stackoverflow.com/questions/34669707/receiving-response-using-afnetworking-in-swift/34670199#34670199 – imjaydeep Jan 08 '16 at 10:31

1 Answers1

0

By default cocoapods is creating static libraries for pods, but swift is not supporting static libraries. So to use cocoapods with swift you should specify to use dynamic framework. For that include following line to your Podfile

use_frameworks!

For more info go through

https://blog.cocoapods.org/CocoaPods-0.36/

http://www.raywenderlich.com/97014/use-cocoapods-with-swift

Update Also be aware that AFHTTPRequestOperationManager and other NSURLConnection related classes are not available in AFNetworking 3.x.

Johnykutty
  • 12,091
  • 13
  • 59
  • 100