qiniu / happy-dns-objc

dns library for objective c
MIT License
506 stars 83 forks source link

Happy DNS for Objective-C

@qiniu on weibo LICENSE Build Status GitHub release codecov Platform

用途

调用系统底层Dns解析库,可以使用 114 等第三方 dns 解析,可以使用 Doh 协议的 Dns 解析方案,也可以集成 dnspod 等 httpdns。另外也有丰富的 hosts 域名配置。

安装

通过 CocoaPods

pod "HappyDNS"

通过 Swift Package Manager (Xcode 11+)

App 对接:
File -> Swift Packages -> Add Package Dependency,输入 HappyDNS 库链接,选择相应版本即可
库链接: https://github.com/qiniu/happy-dns-objc

库对接:
let package = Package(
    dependencies: [
        .package(url: "https://github.com/qiniu/happy-dns-objc", from: "1.0.4")
    ],
    // ...
)

运行环境

使用方法

* 返回 IP 列表

 NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:[QNResolver systemResolver]];
[array addObject:[[QNResolver alloc] initWithAddress:@"119.29.29.29"]];
[array addObject:[QNDohResolver resolverWithServer:@"https://dns.alidns.com/dns-query"]];
QNDnsManager *dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];
NSArray <QNRecord *> *records = [dns queryRecords:@"www.qiniu.com"];

* url 请求,返回一个IP 替换URL 里的domain

NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:[QNResolver systemResolver]];
[array addObject:[[QNResolver alloc] initWithAddress:@"119.29.29.29"]];
QNDnsManager *dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];
NSURL *u = [[NSURL alloc] initWithString:@"rtmp://www.qiniu.com/abc?q=1"];
NSURL *u2 = [dns queryAndReplaceWithIP:u];
$ xctool -workspace HappyDNS.xcworkspace -scheme "HappyDNS_Mac" -sdk macosx -configuration Release test -test-sdk macosx

指定测试

可以在单元测试上修改,熟悉使用

常见问题

代码贡献

详情参考代码提交指南

贡献记录

联系我们

代码许可

The MIT License (MIT).详情见 License文件.