WhiteDnsHelper 0.1.0

WhiteDnsHelper 0.1.0

leavesster 维护。



  • 作者:leavesster
  • leavesster

WhiteDnsHelper

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,然后先从 Example 目录运行 pod install

要求

安装

WhiteDnsHelper 可通过 CocoaPods 获取。要安装,只需将以下行添加到您的 Podfile 中

pod 'WhiteDnsHelper'

如何使用

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //异步查询dns
    [[WhiteDnsManager shareInstance] querySdkDomain];
});

// WKWebview 拦截方式
Class cls = NSClassFromString(@"WKBrowsingContextController");
SEL sel = NSSelectorFromString(@"registerSchemeForCustomProtocol:");
if ([(id)cls respondsToSelector:sel]) {
    
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    // 把 http 和 https 请求交给 NSURLProtocol 处理
    [(id)cls performSelector:sel withObject:@"http"];
    [(id)cls performSelector:sel withObject:@"https"];
#pragma clang diagnostic pop

}
[NSURLProtocol registerClass:[WhiteDnsProtocol class]];

demo 默认提供了一个可测试的房间 uuid 以及 roomToken,用于加入和初始化操作。

在 WhiteDnsProtocol.m 中的以下方法

+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request

log message 断点中加入 mutableReqeust: @[mutableReqeust description]@,即在控制台观察到类似结果:

截图

注意点:

httpdnsc 需要有降级方案,建议在连接失败后主动切换。目前推荐在 White-SDK-iOS 加入房间或回放房间时,设置超时记录(目前 SDK 会无限连接),超时后再次尝试拦截。

授权

WhiteDnsHelper 在 MIT 许可下可用。请参阅 LICENSE 文件以获取更多信息。