Created
April 17, 2018 11:30
-
-
Save AmatsuZero/7a687431b0fa54bf1fc8c4a947225fdc to your computer and use it in GitHub Desktop.
解决RN证书信任的问题(尚未测试)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <React/RCTNetworking.h> | |
@interface RCTNetworkTask (SelfSignCert) | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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