TYKNetwork 配置https 及解决崩溃的问题

适配https请求


YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
    config.baseUrl = LBDR_Service;
    //    // 验证公钥和证书的其他信息
    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
    // /先导入证书
    NSString *cerPath = [[NSBundle mainBundle] pathForResource:user_cername ofType:@"cer"];//证书的路径
    NSData *certData = [NSData dataWithContentsOfFile:cerPath];
    securityPolicy.allowInvalidCertificates = YES;
    securityPolicy.validatesDomainName = YES;
    securityPolicy.pinnedCertificates = [NSSet setWithObject:certData];
    [config setSecurityPolicy:securityPolicy];

如果报错
A security policy configured with AFSSLPinningModeCertificate can only be applied on a manager with a secure base URL
是因为AFNetwork没有获取到url导致的
修改YTKNetworkAgent.m文件的init方法,就能解决这个问题

_manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:_config.sessionConfiguration];

修改为

_manager = [[AFHTTPSessionManager alloc] initWithBaseURL:_config.baseUrl sessionConfiguration:_config.sessionConfiguration];

或者

_manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"你的url"] sessionConfiguration:_config.sessionConfiguration];

你可能感兴趣的:(TYKNetwork 配置https 及解决崩溃的问题)