{"id":13682135,"url":"https://github.com/tonymillion/Reachability","last_synced_at":"2025-04-30T06:34:02.870Z","repository":{"id":1835200,"uuid":"2759563","full_name":"tonymillion/Reachability","owner":"tonymillion","description":"ARC and GCD Compatible Reachability Class for iOS and MacOS. Drop in replacement for Apple Reachability","archived":false,"fork":false,"pushed_at":"2024-04-12T15:55:39.000Z","size":142,"stargazers_count":6980,"open_issues_count":69,"forks_count":1259,"subscribers_count":268,"default_branch":"master","last_synced_at":"2024-10-29T10:54:44.598Z","etag":null,"topics":["apple","objective-c","reachability","wwan"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"kalenjordan/Sample-Code","license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tonymillion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","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":"2011-11-12T00:45:36.000Z","updated_at":"2024-10-29T00:45:39.000Z","dependencies_parsed_at":"2024-03-28T07:24:31.000Z","dependency_job_id":"1a6f33bb-c46d-43ca-b218-eb17b811991d","html_url":"https://github.com/tonymillion/Reachability","commit_stats":{"total_commits":84,"total_committers":31,"mean_commits":"2.7096774193548385","dds":0.5,"last_synced_commit":"09c6b3adac6a6a977d7a7151d52192878158d216"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonymillion%2FReachability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonymillion%2FReachability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonymillion%2FReachability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonymillion%2FReachability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonymillion","download_url":"https://codeload.github.com/tonymillion/Reachability/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222693044,"owners_count":17024035,"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":["apple","objective-c","reachability","wwan"],"created_at":"2024-08-02T13:01:41.184Z","updated_at":"2024-11-12T01:31:10.794Z","avatar_url":"https://github.com/tonymillion.png","language":"Objective-C","readme":"[![Reference Status](https://www.versioneye.com/objective-c/reachability/reference_badge.svg?style=flat)](https://www.versioneye.com/objective-c/reachability/references)\n[![build-status](https://github.com/tonymillion/Reachability/actions/workflows/CI.yml/badge.svg)](https://github.com/tonymillion/Reachability/actions)\n\n# **WARNING** there have been reports of apps being rejected when Reachability is used in a framework. The only solution to this so far is to rename the class.\n\n# Reachability\n\nThis is a drop-in replacement for Apple's `Reachability` class. It is ARC-compatible, and it uses the new GCD methods to notify of network interface changes.\n\nIn addition to the standard `NSNotification`, it supports the use of blocks for when the network becomes reachable and unreachable.\n\nFinally, you can specify whether a WWAN connection is considered \"reachable\".\n\n*DO NOT OPEN BUGS UNTIL YOU HAVE TESTED ON DEVICE*\n\n**BEFORE YOU OPEN A BUG ABOUT iOS6/iOS5 build errors, use Tag 3.2 or 3.1 as they support assign types**\n\n## Requirements\n\nOnce you have added the `.h/m` files to your project, simply:\n\n* Go to the `Project-\u003eTARGETS-\u003eBuild Phases-\u003eLink Binary With Libraries`.\n* Press the plus in the lower left of the list.\n* Add `SystemConfiguration.framework`.\n\nBoom, you're done.\n\n## Examples\n\n### Block Example\n\nThis sample uses blocks to notify when the interface state has changed. The blocks will be called on a **BACKGROUND THREAD**, so you need to dispatch UI updates onto the main thread.\n\n#### In Objective-C\n\n```objc\n// Allocate a reachability object\nReachability* reach = [Reachability reachabilityWithHostname:@\"www.google.com\"];\n\n// Set the blocks\nreach.reachableBlock = ^(Reachability*reach)\n{\n    // keep in mind this is called on a background thread\n    // and if you are updating the UI it needs to happen\n    // on the main thread, like this:\n\n    dispatch_async(dispatch_get_main_queue(), ^{\n        NSLog(@\"REACHABLE!\");\n    });\n};\n\nreach.unreachableBlock = ^(Reachability*reach)\n{\n    NSLog(@\"UNREACHABLE!\");\n};\n\n// Start the notifier, which will cause the reachability object to retain itself!\n[reach startNotifier];\n```\n\n### In Swift 3\n\n```swift\nimport Reachability\n\nvar reach: Reachability?\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n        // Allocate a reachability object\n        self.reach = Reachability.forInternetConnection()\n        \n        // Set the blocks\n        self.reach!.reachableBlock = {\n            (reach: Reachability?) -\u003e Void in\n            \n            // keep in mind this is called on a background thread\n            // and if you are updating the UI it needs to happen\n            // on the main thread, like this:\n            DispatchQueue.main.async {\n                print(\"REACHABLE!\")\n            }\n        }\n        \n        self.reach!.unreachableBlock = {\n            (reach: Reachability?) -\u003e Void in\n            print(\"UNREACHABLE!\")\n        }\n        \n        self.reach!.startNotifier()\n    \n        return true\n}\n```\n\n### `NSNotification` Example\n\nThis sample will use `NSNotification`s to notify when the interface has changed. They will be delivered on the **MAIN THREAD**, so you *can* do UI updates from within the function.\n\nIn addition, it asks the `Reachability` object to consider the WWAN (3G/EDGE/CDMA) as a non-reachable connection (you might use this if you are writing a video streaming app, for example, to save the user's data plan).\n\n#### In Objective-C\n\n```objc\n// Allocate a reachability object\nReachability* reach = [Reachability reachabilityWithHostname:@\"www.google.com\"];\n\n// Tell the reachability that we DON'T want to be reachable on 3G/EDGE/CDMA\nreach.reachableOnWWAN = NO;\n\n// Here we set up a NSNotification observer. The Reachability that caused the notification\n// is passed in the object parameter\n[[NSNotificationCenter defaultCenter] addObserver:self\n                                         selector:@selector(reachabilityChanged:)\n                                             name:kReachabilityChangedNotification\n                                           object:nil];\n\n[reach startNotifier];\n```\n\n#### In Swift 3\n\n```swift\nimport Reachability\n\nvar reach: Reachability?\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n    // Allocate a reachability object\n    self.reach = Reachability.forInternetConnection()\n    \n    // Tell the reachability that we DON'T want to be reachable on 3G/EDGE/CDMA\n    self.reach!.reachableOnWWAN = false\n    \n    // Here we set up a NSNotification observer. The Reachability that caused the notification\n    // is passed in the object parameter\n    NotificationCenter.default.addObserver(\n        self,\n        selector: #selector(reachabilityChanged),\n        name: NSNotification.Name.reachabilityChanged,\n        object: nil\n    )\n    \n    self.reach!.startNotifier()\n    \n    return true\n}\n        \nfunc reachabilityChanged(notification: NSNotification) {\n    if self.reach!.isReachableViaWiFi() || self.reach!.isReachableViaWWAN() {\n        print(\"Service available!!!\")\n    } else {\n        print(\"No service available!!!\")\n    }\n}\n```\n\n## Tell the world\n\nHead over to [Projects using Reachability](https://github.com/tonymillion/Reachability/wiki/Projects-using-Reachability) and add your project for \"Maximum Wins!\".\n","funding_links":[],"categories":["Objective-C","Objective-C  Stars 1000以内排名整理","OOM-Leaks-Crash","wwan","iOS"],"sub_categories":["Networks","网络"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonymillion%2FReachability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonymillion%2FReachability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonymillion%2FReachability/lists"}