weex https 设置

2020-01-14  本文已影响0人  张漂亮1号

在android上:

扩展一个Adapter,继承DefaultWXHttpAdapter

之后在初始化Engine的时候注册它:

setHttpAdapter(new BingoWXHttpAdapter())

在iOS上

继承WXResourceRequestHandlerDefaultImpl实现didReceiveChallenge,具体代码如下:
#import <Foundation/Foundation.h>
#import "WXResourceRequestHandlerDefaultImpl.h"
#import "WXResourceRequestHandler.h"

@interface BingoWXNetworkImpl : WXResourceRequestHandlerDefaultImpl <WXResourceRequestHandler,NSURLSessionDataDelegate>

@end

#import "BingoWXNetworkImpl.h"

@implementation BingoWXNetworkImpl

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * __nullable credential))completionHandler {
    
    //    NSURLSessionAuthChallengeUseCredential = 0, 使用(信任)证书
    //    NSURLSessionAuthChallengePerformDefaultHandling = 1, 默认,忽略
    //    NSURLSessionAuthChallengeCancelAuthenticationChallenge = 2,   取消
    //    NSURLSessionAuthChallengeRejectProtectionSpace = 3,      这次取消,下载次还来问
    
    NSLog(@"%@>>>>>>>>>>>>>>>>>>>>>>>>",challenge.protectionSpace);
    // 如果是请求证书信任,我们再来处理,其他的不需要处理
    if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
        NSURLCredential *cre = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
        // 调用block
        completionHandler(NSURLSessionAuthChallengeUseCredential,cre);
    }
}
@end
在这里插入图片描述
在这里插入图片描述

更多详解:
喜欢可以加@群号:913934649

简书: https://www.jianshu.com/u/88db5f15770d

csdn:https://me.csdn.net/beyondforme

掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7

上一篇 下一篇

猜你喜欢

热点阅读