{"id":15874592,"url":"https://github.com/rudifa/ios-testlaunch","last_synced_at":"2025-04-01T23:21:25.442Z","repository":{"id":74524012,"uuid":"251749757","full_name":"rudifa/iOS-TestLaunch","owner":"rudifa","description":"Demos the operation of a NetworkMonitor singleton in an iOS application.","archived":false,"fork":false,"pushed_at":"2020-04-03T13:47:04.000Z","size":284,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T15:13:51.037Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rudifa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-03-31T21:44:17.000Z","updated_at":"2024-01-19T10:34:27.000Z","dependencies_parsed_at":"2023-03-13T20:17:09.008Z","dependency_job_id":null,"html_url":"https://github.com/rudifa/iOS-TestLaunch","commit_stats":null,"previous_names":["rudifa/ios-testlaunch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2FiOS-TestLaunch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2FiOS-TestLaunch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2FiOS-TestLaunch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2FiOS-TestLaunch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rudifa","download_url":"https://codeload.github.com/rudifa/iOS-TestLaunch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246725459,"owners_count":20823642,"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-10-06T01:40:45.435Z","updated_at":"2025-04-01T23:21:25.422Z","avatar_url":"https://github.com/rudifa.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  TestLaunch\n\n### 1. demonstrate the operation of a NetworkMonitor\n\n`class NetworkMonitor` uses `NWPathMonitor()` from Apple's `Network` kit.\n\n`NetworkMonitor` is a singleton, providing the `isConnected` status to any of the app's\nview controllers.\n\n`NetworkMonitor.shared` usage in a ViewController:\n\n 1. get the current state when you need it\n\n```\nprint(NetworkMonitor.shared.connected ? \"is connected\" : \"is disconnected\"\n```\n 2. add a handler to get a notification when the connectivity changed\n\n```\n     NetworkMonitor.shared.handler = { isConnected in\n         print(isConnected ? \"is connected\" : \"is disconnected\")\n     }\n```\n 3. if the handler references the view controller's self, it must declare `[weak self]`\n    to avoid memory retention cycles\n\n```\n     NetworkMonitor.shared.handler = { [weak self] isConnected in\n         DispatchQueue.main.async {\n             self?.connectedLabel.text = isConnected ? \"connected\" : \"disconnected\"\n         }\n     }\n```\n\nSee also:\n\n[Network Framework in iOS: How to Monitor Network Status Changes](https://www.appcoda.com/network-framework/)\n\n[What Is a Singleton and How To Create One In Swift](https://cocoacasts.com/what-is-a-singleton-and-how-to-create-one-in-swift)\n\n[Weak self and unowned self explained in Swift](https://www.avanderlee.com/swift/weak-self/)\n\n\nNotes:\n1. The app consists of several ViewControllers which use Show segues to present siblings and unwind segues to return to the controller that presented them.\n    The app contains a NetworkMonitor.shared which runs its monitoring while the app is running.\n\n2. The app may go into the background and later come back from background.\n\n3. Each ViewController shall have a Network StatusLabel just underneath the Status Bar.\nStatusLabel shall be invisible (hidden) whenever the device is connected to the internet, and visible with text \"∆ No Network\" when disconnected.\n\nStatusLabel shall be updated or kept up to date:\n3.1 when a presented ViewController appears on the screen (hiding the presenting VC)\n3.2 when a presented ViewController disappears from the screen (unhiding the presenting VC)\n3.3 when the connectivity changes\n3.4 when the app comes back from the background\n\nCurrent concepts and principles:\n- NetworkMonitor.shared is static, therefore it is initialized on the first access after the app start.\n- NetworkMonitor monitors the network connection status until the app exits.\n- ViewControllers wishing to display the connection status must install a handler.\n- NetworkMonitor will call the handler upon its installation and when the connection status changes.\n- Only one client's handler can be instaled at a time.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudifa%2Fios-testlaunch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frudifa%2Fios-testlaunch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudifa%2Fios-testlaunch/lists"}