原因是iOS16增强了对非标准https的校验
解决办法是找到框架的网络请求类:类似 XXNetwork
然后重写其挑战方法
XXNetwork+YYY.h
NS_ASSUME_NONNULL_BEGIN
@interface xxNetwork :NSURLProtocol
@end
@interface xxNetwork (YYY)
@end
NS_ASSUME_NONNULL_END
xxNetwork+YYY.m
#import "xxNetwork+YYY.h"
#import <objc/runtime.h>
@implementation xxNetwork (YYY)
+ (void)load{
{
Method originalMethod = class_getInstanceMethod([self class], @selector(URLSession:dataTask:didReceiveResponse:completionHandler:));
Method swizzledMethod = class_getInstanceMethod([self class], @selector(URLSession:dataTask:didReceiveResponse:completionHandlerS:));
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler;
{
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
completionHandler(NSURLSessionAuthChallengeUseCredential , credential);
}