I want to allow invalid SSL certificates with AFNetworking

前端 未结 13 698
南笙
南笙 2020-12-02 10:11

I want to allow invalid SSL certificates. My main code is below:

myClient = [[MyClient alloc] init];
[myClient getHtml:@\"/path/to/the/distination.html\"];
<         


        
13条回答
  •  粉色の甜心
    2020-12-02 10:39

    I am using RestKit so

    client.allowsInvalidSSLCertificate = YES;
    

    does not work. The option is not propagated to the operations created by restkit.

    I am using cocoapods so any changes in the pch file or the pods project get overriden. The "hack" I have been using is a cocoapod post-install operation that adds the required preprocessor definition. At the end of my pod file I have added:

    post_install do |installer_representation|
      installer_representation.project.targets.each do |target|
        if target.name == 'Pods-AFNetworking'
          target.build_configurations.each do |config|
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << '_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_=1'
          end
        end
      end
    end
    

提交回复
热议问题