Skip to content

Instantly share code, notes, and snippets.

@AmatsuZero
Created April 17, 2018 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmatsuZero/7a687431b0fa54bf1fc8c4a947225fdc to your computer and use it in GitHub Desktop.
Save AmatsuZero/7a687431b0fa54bf1fc8c4a947225fdc to your computer and use it in GitHub Desktop.
解决RN证书信任的问题(尚未测试)
#import <React/RCTNetworking.h>
@interface RCTNetworkTask (SelfSignCert)
@end
#import "RCTNetworkTask+SelfSignCert.h"
#import <objc/runtime.h>
@implementation RCTNetworkTask (SelfSignCert)
+(void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method handler = class_getInstanceMethod(self, @selector(customChallengeHanlderForSession:chanllenge:completionHandler:));
class_addMethod(NSClassFromString(@"RCTHTTPRequestHandler"), @selector(URLSession:didReceiveChallenge:completionHandler:), (IMP)handler, method_getTypeEncoding(handler));
});
}
- (void)customChallengeHanlderForSession:(NSURLSession*)session
chanllenge: (NSURLAuthenticationChallenge*)challenge
completionHandler: (void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment