{"id":1612,"url":"https://github.com/qiniu/happy-dns-objc","last_synced_at":"2025-05-16T15:08:07.515Z","repository":{"id":37664826,"uuid":"37804383","full_name":"qiniu/happy-dns-objc","owner":"qiniu","description":"dns library for objective c","archived":false,"fork":false,"pushed_at":"2024-05-13T07:42:38.000Z","size":1013,"stargazers_count":509,"open_issues_count":12,"forks_count":83,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-05T20:17:25.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qiniu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-21T10:02:43.000Z","updated_at":"2025-04-26T07:18:45.000Z","dependencies_parsed_at":"2024-01-07T22:23:28.038Z","dependency_job_id":"a4b80de8-2881-49a5-aae2-5ed63d69c21f","html_url":"https://github.com/qiniu/happy-dns-objc","commit_stats":{"total_commits":174,"total_committers":14,"mean_commits":"12.428571428571429","dds":0.4770114942528736,"last_synced_commit":"b1d31d568eb26ce6e7d88f1e492a1da4b2eddb79"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiniu%2Fhappy-dns-objc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiniu%2Fhappy-dns-objc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiniu%2Fhappy-dns-objc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiniu%2Fhappy-dns-objc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qiniu","download_url":"https://codeload.github.com/qiniu/happy-dns-objc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253518982,"owners_count":21921084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:51.373Z","updated_at":"2025-05-16T15:08:02.509Z","avatar_url":"https://github.com/qiniu.png","language":"Objective-C","funding_links":[],"categories":["Networking"],"sub_categories":["Video","Other free courses"],"readme":"# Happy DNS for Objective-C\n\n[![@qiniu on weibo](http://img.shields.io/badge/weibo-%40qiniutek-blue.svg)](http://weibo.com/qiniutek)\n[![LICENSE](https://img.shields.io/github/license/qiniu/happy-dns-objc.svg)](https://github.com/qiniu/happy-dns-objc/blob/master/LICENSE)\n[![Build Status](https://travis-ci.org/qiniu/happy-dns-objc.svg?branch=master)](https://travis-ci.org/qiniu/happy-dns-objc)\n[![GitHub release](https://img.shields.io/github/v/tag/qiniu/happy-dns-objc.svg?label=release)](https://github.com/qiniu/happy-dns-objc/releases)\n[![codecov](https://codecov.io/gh/qiniu/happy-dns-objc/branch/master/graph/badge.svg)](https://codecov.io/gh/qiniu/happy-dns-objc)\n![Platform](http://img.shields.io/cocoapods/p/HappyDNS.svg)\n\n## 用途\n\n调用系统底层Dns解析库，可以使用 114 等第三方 dns 解析，可以使用 Doh 协议的 Dns 解析方案，也可以集成 dnspod 等 httpdns。另外也有丰富的 hosts 域名配置。\n\n## 安装\n\n通过 CocoaPods\n```ruby\npod \"HappyDNS\"\n```\n\n通过 Swift Package Manager (Xcode 11+)\n```\nApp 对接:\nFile -\u003e Swift Packages -\u003e Add Package Dependency，输入 HappyDNS 库链接，选择相应版本即可\n库链接: https://github.com/qiniu/happy-dns-objc\n\n库对接:\nlet package = Package(\n    dependencies: [\n        .package(url: \"https://github.com/qiniu/happy-dns-objc\", from: \"1.0.4\")\n    ],\n    // ...\n)\n\n```\n\n## 运行环境\n\n\n## 使用方法\n＊ 返回 IP 列表\n```\n NSMutableArray *array = [[NSMutableArray alloc] init];\n[array addObject:[QNResolver systemResolver]];\n[array addObject:[[QNResolver alloc] initWithAddress:@\"119.29.29.29\"]];\n[array addObject:[QNDohResolver resolverWithServer:@\"https://dns.alidns.com/dns-query\"]];\nQNDnsManager *dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];\nNSArray \u003cQNRecord *\u003e *records = [dns queryRecords:@\"www.qiniu.com\"];\n```\n＊ url 请求，返回一个IP 替换URL 里的domain\n```\nNSMutableArray *array = [[NSMutableArray alloc] init];\n[array addObject:[QNResolver systemResolver]];\n[array addObject:[[QNResolver alloc] initWithAddress:@\"119.29.29.29\"]];\nQNDnsManager *dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];\nNSURL *u = [[NSURL alloc] initWithString:@\"rtmp://www.qiniu.com/abc?q=1\"];\nNSURL *u2 = [dns queryAndReplaceWithIP:u];\n```\n* 兼容 getaddrinfo, 方便底层 C 代码接入\n```\nstatic QNDnsManager *dns = nil;\ndns = [[QNDnsManager alloc] init:@[ [QNResolver systemResolver] ] networkInfo:nil];\n[QNDnsManager setGetAddrInfoBlock:^NSArray *(NSString *host) {\n        return [dns query:host];\n    }];\nstruct addrinfo hints = {0};\nstruct addrinfo *ai = NULL;\nint x = qn_getaddrinfo(host, \"http\", \u0026hints, \u0026ai);\nqn_freeaddrinfo(ai); // 也可以用系统的freeaddrinfo, 代码一致，不过最好用这个\n```\n### 运行测试\n\n``` bash\n$ xctool -workspace HappyDNS.xcworkspace -scheme \"HappyDNS_Mac\" -sdk macosx -configuration Release test -test-sdk macosx\n```\n\n### 指定测试\n\n可以在单元测试上修改，熟悉使用\n\n``` bash\n```\n\n## 常见问题\n\n- 如果碰到其他编译错误，请参考 CocoaPods 的 [troubleshooting](http://guides.cocoapods.org/using/troubleshooting.html)\n- httpdns 在**ios8** 时不支持 nat64 模式下 IP 直接访问url，原因是 NSUrlConnection 不支持。无论是用http://119.29.29.29/d 还是http://[64:ff9b::771d:1d1d]/d 都不行，此时可以使用localdns方式。\n- 如果软件有国外的使用情况时，建议初始化程序采取这样的方式\n```Objective-C\nQNDnsManager *dns;\nif([QNDnsManager needHttpDns]){\n    NSMutableArray *array = [[NSMutableArray alloc] init];\n    [array addObject:[[QNResolver alloc] initWithAddress:@\"119.29.29.29\"]];\n    [array addObject:[QNResolver systemResolver]];\n    dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];\n}else{\n    NSMutableArray *array = [[NSMutableArray alloc] init];\n    [array addObject:[QNResolver systemResolver]];\n    [array addObject:[[QNResolver alloc] initWithAddress:@\"114.114.114.114\"]];\n    dns = [[QNDnsManager alloc] init:array networkInfo:[QNNetworkInfo normal]];\n}\n```\n\n## 代码贡献\n\n详情参考[代码提交指南](https://github.com/qiniu/happy-dns-objc/blob/master/CONTRIBUTING.md)。\n\n## 贡献记录\n\n- [所有贡献者](https://github.com/qiniu/happy-dns-objc/contributors)\n\n## 联系我们\n\n- 如果有什么问题，可以到问答社区提问，[问答社区](http://qiniu.segmentfault.com/)\n- 如果发现了bug， 欢迎提交 [issue](https://github.com/qiniu/happy-dns-objc/issues)\n- 如果有功能需求，欢迎提交 [issue](https://github.com/qiniu/happy-dns-objc/issues)\n- 如果要提交代码，欢迎提交 pull request\n- 欢迎关注我们的[微信](http://www.qiniu.com/#weixin) [微博](http://weibo.com/qiniutek)，及时获取动态信息。\n\n## 代码许可\n\nThe MIT License (MIT).详情见 [License文件](https://github.com/qiniu/happy-dns-objc/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiniu%2Fhappy-dns-objc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqiniu%2Fhappy-dns-objc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiniu%2Fhappy-dns-objc/lists"}