{"id":28619638,"url":"https://github.com/eleme/sparrowsdk-ios","last_synced_at":"2025-10-20T06:31:39.809Z","repository":{"id":62455908,"uuid":"147170018","full_name":"eleme/SparrowSDK-iOS","owner":"eleme","description":null,"archived":false,"fork":false,"pushed_at":"2019-04-29T12:11:03.000Z","size":1379,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-18T16:52:02.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/eleme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-03T07:49:30.000Z","updated_at":"2019-12-26T01:37:30.000Z","dependencies_parsed_at":"2022-11-01T23:45:57.884Z","dependency_job_id":null,"html_url":"https://github.com/eleme/SparrowSDK-iOS","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/eleme/SparrowSDK-iOS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FSparrowSDK-iOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FSparrowSDK-iOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FSparrowSDK-iOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FSparrowSDK-iOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eleme","download_url":"https://codeload.github.com/eleme/SparrowSDK-iOS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eleme%2FSparrowSDK-iOS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259400475,"owners_count":22851816,"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":"2025-06-12T04:40:51.227Z","updated_at":"2025-10-20T06:31:39.731Z","avatar_url":"https://github.com/eleme.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SparrowSDK\n\nSparrowSDK 是配合 [Sparrow](https://github.com/eleme/Sparrow) Server 使用的 iOS 端 SDK，集成后可以不需要修改业务代码，即可 Mock API。\n\n## 集成\n\n```ruby\npod 'SparrowSDK', :configurations =\u003e ['Debug']\n```\n\n## 集成\n\n```ruby\npod 'SparrowSDK', :configurations =\u003e ['Debug']\n```\n\n在 `AppDelegate` 的  `didFinishLaunchingWithOptions` 中加上以下代码：\n\n```objc\nSPROptions *options = [SPROptions new];\noptions.hostURL = @\"http://your.sparrow.host\";\n[SparrowSDK startWithOption:options];\n```\n\nSparrow 使用了 `NSURLProtocol ` 监控网络，如果您还有其他的 `NSURLProtocol ` 网络监控，可以将 `[SPRURLProtocol class]` 添加进去。\n\n## 简介\n\n当部署好 Sparrow 服务器，并集成好 SDK 后，打开您的 app，会看到一个 Sparrow 的悬浮框。\n\n\n\n![](Res/sparrow-sdk-001.png)\n\n点击左上角的悬浮窗，可以进入 Sparrow 的控制中心\n\n![](Res/sparrow-sdk-003.png)\n\n点击『重选项目』。如果没有登录过，会弹出登录页面\n\n![](Res/sparrow-sdk-004.png)\n\n输入在 Sparrow 系统上的账户名密码，或者使用『扫码登录』。\n\n如果使用扫码登录，二维码在 Sparrow 系统登录后的导航栏处。\n\n![](Res/sparrow-sdk-005.png)\n\n点击后就会弹出二维码，一分钟有效。使用 SparrowSDK 扫码可以免输入登录。\n\n登录后，在『选择项目页』就会拉取到登录账户有权限访问的所有项目列表。\n\n![](Res/sparrow-sdk-007.png)\n\n点击右上角『选择』 -\u003e 选择您想同步的项目 -\u003e 点击完成 -\u003e 自动返回到控制中心，拉取到同步的 API 列表\n\n![](Res/sparrow-sdk-008.png)\n\n现在我们拉取了『Welcome』项目里的所有 API，可以观察到和我们首页访问的三个示例 API path 部分项目。\n\n点击返回，回到首页，这时，我们再点击三个按钮，就可以访问到在 Sparrow 系统里设置好的返回数据。\n\n![](Res/sparrow-sdk-009.png)\n\n\n\n## Mock 工作方式\n\nSparrowSDK 的使用没有侵入性。\n\n大多数 Mock 系统需要更改移动端的网络请求代码，对开发过程造成了很多不必要的麻烦，甚至导致开发者会忘记改回代码，将访问 Mock 服务器的代码发布到线上。\n\nSparrowSDK 的工作方式是：\n\n1. 拦截所有的网络请求\n2. 进行过滤，如果一个 NSURLRequest 的 `path` 部分和同步下来的 API `path` 部分相同，则进行转发，将请求转发哦到 Sparrow 服务器上\n3. 接收到 Sparrow 服务器上对应的数据\n\n通过转发的拦截转发，开发过程中不需要做任何网络请求的代码改动。**如果在 Sparrow 系统上做了 API 的更改、增加、删除，只需要在继承了 SparrowSDK 的 App 上摇一摇手机，即可同步**。\n\n当然，你也可以在 Sparrow 的设置页面关闭『摇一摇』功能。\n\n![](Res/sparrow-sdk-010.png)\n\n如果 Sparrow 的服务器位置更改了，或者自行搭建了 Sparrow 服务器，可以通过更改上图中的『Sparrow Host』来保证 SparrowSDK 的正常使用。\n\n## 自定义\n\nSparrow 也提供了自定义的启动样式，您可以不使用悬浮框样式：\n\n```objc\nSPROptions *options = [SPROptions new];\noptions.hostURL = @\"http://alta1-lpd-talaris-team-app-download-1.vm.elenet.me\";\noptions.sytle = SPROptionsSytleCustom;\n[SparrowSDK startWithOption:options];\n```\n\n如果您使用 `SPROptionsSytleCustom` 作为样式，SparrowSDK 在初始化后将不会出现悬浮框，您可以手动调用以下代码打开 SparrowSDK 的控制中心：\n\n```objc\n[SparrowSDK showControlPage];\n```\n\n或使用以下代码关闭 SparrowSDK 的控制中心：\n\n```objc\n[SparrowSDK dismissControlPage];\n```\n\n## Other\n\n如果在使用过程中有任何问题，欢迎联系我（coderfish@163.com | 周凌宇）😘\n\nAnyway，希望用的开心~","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleme%2Fsparrowsdk-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feleme%2Fsparrowsdk-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feleme%2Fsparrowsdk-ios/lists"}