├── NetworkSpeed.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── QingY-Mac.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── iFD.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── QingY-Mac.xcuserdatad │ └── xcschemes │ │ ├── NetworkSpeed.xcscheme │ │ └── xcschememanagement.plist │ └── iFD.xcuserdatad │ └── xcschemes │ ├── NetworkSpeed.xcscheme │ └── xcschememanagement.plist ├── NetworkSpeed ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── NetWorkSpeedMonitor.h ├── NetWorkSpeedMonitor.m ├── Reachability.h ├── Reachability.m ├── ViewController.h ├── ViewController.m └── main.m ├── NetworkSpeedTests ├── Info.plist └── NetworkSpeedTests.m └── NetworkSpeedUITests ├── Info.plist └── NetworkSpeedUITests.m /NetworkSpeed.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A44BB6341BB4F3AB00B290CC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB6331BB4F3AB00B290CC /* main.m */; }; 11 | A44BB6371BB4F3AB00B290CC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB6361BB4F3AB00B290CC /* AppDelegate.m */; }; 12 | A44BB63A1BB4F3AB00B290CC /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB6391BB4F3AB00B290CC /* ViewController.m */; }; 13 | A44BB63D1BB4F3AB00B290CC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A44BB63B1BB4F3AB00B290CC /* Main.storyboard */; }; 14 | A44BB63F1BB4F3AB00B290CC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A44BB63E1BB4F3AB00B290CC /* Assets.xcassets */; }; 15 | A44BB6421BB4F3AB00B290CC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A44BB6401BB4F3AB00B290CC /* LaunchScreen.storyboard */; }; 16 | A44BB64D1BB4F3AB00B290CC /* NetworkSpeedTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB64C1BB4F3AB00B290CC /* NetworkSpeedTests.m */; }; 17 | A44BB6581BB4F3AB00B290CC /* NetworkSpeedUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB6571BB4F3AB00B290CC /* NetworkSpeedUITests.m */; }; 18 | A44BB6691BB4F3EA00B290CC /* NetWorkSpeedMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB6661BB4F3EA00B290CC /* NetWorkSpeedMonitor.m */; settings = {ASSET_TAGS = (); }; }; 19 | A44BB66A1BB4F3EA00B290CC /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = A44BB6681BB4F3EA00B290CC /* Reachability.m */; settings = {ASSET_TAGS = (); }; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | A44BB6491BB4F3AB00B290CC /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = A44BB6271BB4F3AB00B290CC /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = A44BB62E1BB4F3AB00B290CC; 28 | remoteInfo = NetworkSpeed; 29 | }; 30 | A44BB6541BB4F3AB00B290CC /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = A44BB6271BB4F3AB00B290CC /* Project object */; 33 | proxyType = 1; 34 | remoteGlobalIDString = A44BB62E1BB4F3AB00B290CC; 35 | remoteInfo = NetworkSpeed; 36 | }; 37 | /* End PBXContainerItemProxy section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | A44BB62F1BB4F3AB00B290CC /* NetworkSpeed.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetworkSpeed.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | A44BB6331BB4F3AB00B290CC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 42 | A44BB6351BB4F3AB00B290CC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 43 | A44BB6361BB4F3AB00B290CC /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 44 | A44BB6381BB4F3AB00B290CC /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 45 | A44BB6391BB4F3AB00B290CC /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 46 | A44BB63C1BB4F3AB00B290CC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 47 | A44BB63E1BB4F3AB00B290CC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 48 | A44BB6411BB4F3AB00B290CC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 49 | A44BB6431BB4F3AB00B290CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | A44BB6481BB4F3AB00B290CC /* NetworkSpeedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NetworkSpeedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | A44BB64C1BB4F3AB00B290CC /* NetworkSpeedTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NetworkSpeedTests.m; sourceTree = ""; }; 52 | A44BB64E1BB4F3AB00B290CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | A44BB6531BB4F3AB00B290CC /* NetworkSpeedUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NetworkSpeedUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 54 | A44BB6571BB4F3AB00B290CC /* NetworkSpeedUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NetworkSpeedUITests.m; sourceTree = ""; }; 55 | A44BB6591BB4F3AB00B290CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | A44BB6651BB4F3EA00B290CC /* NetWorkSpeedMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetWorkSpeedMonitor.h; sourceTree = ""; }; 57 | A44BB6661BB4F3EA00B290CC /* NetWorkSpeedMonitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NetWorkSpeedMonitor.m; sourceTree = ""; }; 58 | A44BB6671BB4F3EA00B290CC /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; 59 | A44BB6681BB4F3EA00B290CC /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | A44BB62C1BB4F3AB00B290CC /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | A44BB6451BB4F3AB00B290CC /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | A44BB6501BB4F3AB00B290CC /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | A44BB6261BB4F3AB00B290CC = { 88 | isa = PBXGroup; 89 | children = ( 90 | A44BB6311BB4F3AB00B290CC /* NetworkSpeed */, 91 | A44BB64B1BB4F3AB00B290CC /* NetworkSpeedTests */, 92 | A44BB6561BB4F3AB00B290CC /* NetworkSpeedUITests */, 93 | A44BB6301BB4F3AB00B290CC /* Products */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | A44BB6301BB4F3AB00B290CC /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | A44BB62F1BB4F3AB00B290CC /* NetworkSpeed.app */, 101 | A44BB6481BB4F3AB00B290CC /* NetworkSpeedTests.xctest */, 102 | A44BB6531BB4F3AB00B290CC /* NetworkSpeedUITests.xctest */, 103 | ); 104 | name = Products; 105 | sourceTree = ""; 106 | }; 107 | A44BB6311BB4F3AB00B290CC /* NetworkSpeed */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | A44BB6651BB4F3EA00B290CC /* NetWorkSpeedMonitor.h */, 111 | A44BB6661BB4F3EA00B290CC /* NetWorkSpeedMonitor.m */, 112 | A44BB6671BB4F3EA00B290CC /* Reachability.h */, 113 | A44BB6681BB4F3EA00B290CC /* Reachability.m */, 114 | A44BB6351BB4F3AB00B290CC /* AppDelegate.h */, 115 | A44BB6361BB4F3AB00B290CC /* AppDelegate.m */, 116 | A44BB6381BB4F3AB00B290CC /* ViewController.h */, 117 | A44BB6391BB4F3AB00B290CC /* ViewController.m */, 118 | A44BB63B1BB4F3AB00B290CC /* Main.storyboard */, 119 | A44BB63E1BB4F3AB00B290CC /* Assets.xcassets */, 120 | A44BB6401BB4F3AB00B290CC /* LaunchScreen.storyboard */, 121 | A44BB6431BB4F3AB00B290CC /* Info.plist */, 122 | A44BB6321BB4F3AB00B290CC /* Supporting Files */, 123 | ); 124 | path = NetworkSpeed; 125 | sourceTree = ""; 126 | }; 127 | A44BB6321BB4F3AB00B290CC /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | A44BB6331BB4F3AB00B290CC /* main.m */, 131 | ); 132 | name = "Supporting Files"; 133 | sourceTree = ""; 134 | }; 135 | A44BB64B1BB4F3AB00B290CC /* NetworkSpeedTests */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | A44BB64C1BB4F3AB00B290CC /* NetworkSpeedTests.m */, 139 | A44BB64E1BB4F3AB00B290CC /* Info.plist */, 140 | ); 141 | path = NetworkSpeedTests; 142 | sourceTree = ""; 143 | }; 144 | A44BB6561BB4F3AB00B290CC /* NetworkSpeedUITests */ = { 145 | isa = PBXGroup; 146 | children = ( 147 | A44BB6571BB4F3AB00B290CC /* NetworkSpeedUITests.m */, 148 | A44BB6591BB4F3AB00B290CC /* Info.plist */, 149 | ); 150 | path = NetworkSpeedUITests; 151 | sourceTree = ""; 152 | }; 153 | /* End PBXGroup section */ 154 | 155 | /* Begin PBXNativeTarget section */ 156 | A44BB62E1BB4F3AB00B290CC /* NetworkSpeed */ = { 157 | isa = PBXNativeTarget; 158 | buildConfigurationList = A44BB65C1BB4F3AB00B290CC /* Build configuration list for PBXNativeTarget "NetworkSpeed" */; 159 | buildPhases = ( 160 | A44BB62B1BB4F3AB00B290CC /* Sources */, 161 | A44BB62C1BB4F3AB00B290CC /* Frameworks */, 162 | A44BB62D1BB4F3AB00B290CC /* Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | ); 168 | name = NetworkSpeed; 169 | productName = NetworkSpeed; 170 | productReference = A44BB62F1BB4F3AB00B290CC /* NetworkSpeed.app */; 171 | productType = "com.apple.product-type.application"; 172 | }; 173 | A44BB6471BB4F3AB00B290CC /* NetworkSpeedTests */ = { 174 | isa = PBXNativeTarget; 175 | buildConfigurationList = A44BB65F1BB4F3AB00B290CC /* Build configuration list for PBXNativeTarget "NetworkSpeedTests" */; 176 | buildPhases = ( 177 | A44BB6441BB4F3AB00B290CC /* Sources */, 178 | A44BB6451BB4F3AB00B290CC /* Frameworks */, 179 | A44BB6461BB4F3AB00B290CC /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | A44BB64A1BB4F3AB00B290CC /* PBXTargetDependency */, 185 | ); 186 | name = NetworkSpeedTests; 187 | productName = NetworkSpeedTests; 188 | productReference = A44BB6481BB4F3AB00B290CC /* NetworkSpeedTests.xctest */; 189 | productType = "com.apple.product-type.bundle.unit-test"; 190 | }; 191 | A44BB6521BB4F3AB00B290CC /* NetworkSpeedUITests */ = { 192 | isa = PBXNativeTarget; 193 | buildConfigurationList = A44BB6621BB4F3AB00B290CC /* Build configuration list for PBXNativeTarget "NetworkSpeedUITests" */; 194 | buildPhases = ( 195 | A44BB64F1BB4F3AB00B290CC /* Sources */, 196 | A44BB6501BB4F3AB00B290CC /* Frameworks */, 197 | A44BB6511BB4F3AB00B290CC /* Resources */, 198 | ); 199 | buildRules = ( 200 | ); 201 | dependencies = ( 202 | A44BB6551BB4F3AB00B290CC /* PBXTargetDependency */, 203 | ); 204 | name = NetworkSpeedUITests; 205 | productName = NetworkSpeedUITests; 206 | productReference = A44BB6531BB4F3AB00B290CC /* NetworkSpeedUITests.xctest */; 207 | productType = "com.apple.product-type.bundle.ui-testing"; 208 | }; 209 | /* End PBXNativeTarget section */ 210 | 211 | /* Begin PBXProject section */ 212 | A44BB6271BB4F3AB00B290CC /* Project object */ = { 213 | isa = PBXProject; 214 | attributes = { 215 | LastUpgradeCheck = 0700; 216 | ORGANIZATIONNAME = ifandong; 217 | TargetAttributes = { 218 | A44BB62E1BB4F3AB00B290CC = { 219 | CreatedOnToolsVersion = 7.0; 220 | DevelopmentTeam = 4N8C22Y7VD; 221 | }; 222 | A44BB6471BB4F3AB00B290CC = { 223 | CreatedOnToolsVersion = 7.0; 224 | TestTargetID = A44BB62E1BB4F3AB00B290CC; 225 | }; 226 | A44BB6521BB4F3AB00B290CC = { 227 | CreatedOnToolsVersion = 7.0; 228 | TestTargetID = A44BB62E1BB4F3AB00B290CC; 229 | }; 230 | }; 231 | }; 232 | buildConfigurationList = A44BB62A1BB4F3AB00B290CC /* Build configuration list for PBXProject "NetworkSpeed" */; 233 | compatibilityVersion = "Xcode 3.2"; 234 | developmentRegion = English; 235 | hasScannedForEncodings = 0; 236 | knownRegions = ( 237 | en, 238 | Base, 239 | ); 240 | mainGroup = A44BB6261BB4F3AB00B290CC; 241 | productRefGroup = A44BB6301BB4F3AB00B290CC /* Products */; 242 | projectDirPath = ""; 243 | projectRoot = ""; 244 | targets = ( 245 | A44BB62E1BB4F3AB00B290CC /* NetworkSpeed */, 246 | A44BB6471BB4F3AB00B290CC /* NetworkSpeedTests */, 247 | A44BB6521BB4F3AB00B290CC /* NetworkSpeedUITests */, 248 | ); 249 | }; 250 | /* End PBXProject section */ 251 | 252 | /* Begin PBXResourcesBuildPhase section */ 253 | A44BB62D1BB4F3AB00B290CC /* Resources */ = { 254 | isa = PBXResourcesBuildPhase; 255 | buildActionMask = 2147483647; 256 | files = ( 257 | A44BB6421BB4F3AB00B290CC /* LaunchScreen.storyboard in Resources */, 258 | A44BB63F1BB4F3AB00B290CC /* Assets.xcassets in Resources */, 259 | A44BB63D1BB4F3AB00B290CC /* Main.storyboard in Resources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | A44BB6461BB4F3AB00B290CC /* Resources */ = { 264 | isa = PBXResourcesBuildPhase; 265 | buildActionMask = 2147483647; 266 | files = ( 267 | ); 268 | runOnlyForDeploymentPostprocessing = 0; 269 | }; 270 | A44BB6511BB4F3AB00B290CC /* Resources */ = { 271 | isa = PBXResourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | }; 277 | /* End PBXResourcesBuildPhase section */ 278 | 279 | /* Begin PBXSourcesBuildPhase section */ 280 | A44BB62B1BB4F3AB00B290CC /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | A44BB63A1BB4F3AB00B290CC /* ViewController.m in Sources */, 285 | A44BB6371BB4F3AB00B290CC /* AppDelegate.m in Sources */, 286 | A44BB6341BB4F3AB00B290CC /* main.m in Sources */, 287 | A44BB6691BB4F3EA00B290CC /* NetWorkSpeedMonitor.m in Sources */, 288 | A44BB66A1BB4F3EA00B290CC /* Reachability.m in Sources */, 289 | ); 290 | runOnlyForDeploymentPostprocessing = 0; 291 | }; 292 | A44BB6441BB4F3AB00B290CC /* Sources */ = { 293 | isa = PBXSourcesBuildPhase; 294 | buildActionMask = 2147483647; 295 | files = ( 296 | A44BB64D1BB4F3AB00B290CC /* NetworkSpeedTests.m in Sources */, 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | A44BB64F1BB4F3AB00B290CC /* Sources */ = { 301 | isa = PBXSourcesBuildPhase; 302 | buildActionMask = 2147483647; 303 | files = ( 304 | A44BB6581BB4F3AB00B290CC /* NetworkSpeedUITests.m in Sources */, 305 | ); 306 | runOnlyForDeploymentPostprocessing = 0; 307 | }; 308 | /* End PBXSourcesBuildPhase section */ 309 | 310 | /* Begin PBXTargetDependency section */ 311 | A44BB64A1BB4F3AB00B290CC /* PBXTargetDependency */ = { 312 | isa = PBXTargetDependency; 313 | target = A44BB62E1BB4F3AB00B290CC /* NetworkSpeed */; 314 | targetProxy = A44BB6491BB4F3AB00B290CC /* PBXContainerItemProxy */; 315 | }; 316 | A44BB6551BB4F3AB00B290CC /* PBXTargetDependency */ = { 317 | isa = PBXTargetDependency; 318 | target = A44BB62E1BB4F3AB00B290CC /* NetworkSpeed */; 319 | targetProxy = A44BB6541BB4F3AB00B290CC /* PBXContainerItemProxy */; 320 | }; 321 | /* End PBXTargetDependency section */ 322 | 323 | /* Begin PBXVariantGroup section */ 324 | A44BB63B1BB4F3AB00B290CC /* Main.storyboard */ = { 325 | isa = PBXVariantGroup; 326 | children = ( 327 | A44BB63C1BB4F3AB00B290CC /* Base */, 328 | ); 329 | name = Main.storyboard; 330 | sourceTree = ""; 331 | }; 332 | A44BB6401BB4F3AB00B290CC /* LaunchScreen.storyboard */ = { 333 | isa = PBXVariantGroup; 334 | children = ( 335 | A44BB6411BB4F3AB00B290CC /* Base */, 336 | ); 337 | name = LaunchScreen.storyboard; 338 | sourceTree = ""; 339 | }; 340 | /* End PBXVariantGroup section */ 341 | 342 | /* Begin XCBuildConfiguration section */ 343 | A44BB65A1BB4F3AB00B290CC /* Debug */ = { 344 | isa = XCBuildConfiguration; 345 | buildSettings = { 346 | ALWAYS_SEARCH_USER_PATHS = NO; 347 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 348 | CLANG_CXX_LIBRARY = "libc++"; 349 | CLANG_ENABLE_MODULES = YES; 350 | CLANG_ENABLE_OBJC_ARC = YES; 351 | CLANG_WARN_BOOL_CONVERSION = YES; 352 | CLANG_WARN_CONSTANT_CONVERSION = YES; 353 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 354 | CLANG_WARN_EMPTY_BODY = YES; 355 | CLANG_WARN_ENUM_CONVERSION = YES; 356 | CLANG_WARN_INT_CONVERSION = YES; 357 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 358 | CLANG_WARN_UNREACHABLE_CODE = YES; 359 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 360 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 361 | COPY_PHASE_STRIP = NO; 362 | DEBUG_INFORMATION_FORMAT = dwarf; 363 | ENABLE_STRICT_OBJC_MSGSEND = YES; 364 | ENABLE_TESTABILITY = YES; 365 | GCC_C_LANGUAGE_STANDARD = gnu99; 366 | GCC_DYNAMIC_NO_PIC = NO; 367 | GCC_NO_COMMON_BLOCKS = YES; 368 | GCC_OPTIMIZATION_LEVEL = 0; 369 | GCC_PREPROCESSOR_DEFINITIONS = ( 370 | "DEBUG=1", 371 | "$(inherited)", 372 | ); 373 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 374 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 375 | GCC_WARN_UNDECLARED_SELECTOR = YES; 376 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 377 | GCC_WARN_UNUSED_FUNCTION = YES; 378 | GCC_WARN_UNUSED_VARIABLE = YES; 379 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 380 | MTL_ENABLE_DEBUG_INFO = YES; 381 | ONLY_ACTIVE_ARCH = YES; 382 | SDKROOT = iphoneos; 383 | TARGETED_DEVICE_FAMILY = "1,2"; 384 | }; 385 | name = Debug; 386 | }; 387 | A44BB65B1BB4F3AB00B290CC /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | ALWAYS_SEARCH_USER_PATHS = NO; 391 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 392 | CLANG_CXX_LIBRARY = "libc++"; 393 | CLANG_ENABLE_MODULES = YES; 394 | CLANG_ENABLE_OBJC_ARC = YES; 395 | CLANG_WARN_BOOL_CONVERSION = YES; 396 | CLANG_WARN_CONSTANT_CONVERSION = YES; 397 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 398 | CLANG_WARN_EMPTY_BODY = YES; 399 | CLANG_WARN_ENUM_CONVERSION = YES; 400 | CLANG_WARN_INT_CONVERSION = YES; 401 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 402 | CLANG_WARN_UNREACHABLE_CODE = YES; 403 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 404 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 405 | COPY_PHASE_STRIP = NO; 406 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 407 | ENABLE_NS_ASSERTIONS = NO; 408 | ENABLE_STRICT_OBJC_MSGSEND = YES; 409 | GCC_C_LANGUAGE_STANDARD = gnu99; 410 | GCC_NO_COMMON_BLOCKS = YES; 411 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 412 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 413 | GCC_WARN_UNDECLARED_SELECTOR = YES; 414 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 415 | GCC_WARN_UNUSED_FUNCTION = YES; 416 | GCC_WARN_UNUSED_VARIABLE = YES; 417 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 418 | MTL_ENABLE_DEBUG_INFO = NO; 419 | SDKROOT = iphoneos; 420 | TARGETED_DEVICE_FAMILY = "1,2"; 421 | VALIDATE_PRODUCT = YES; 422 | }; 423 | name = Release; 424 | }; 425 | A44BB65D1BB4F3AB00B290CC /* Debug */ = { 426 | isa = XCBuildConfiguration; 427 | buildSettings = { 428 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 429 | CODE_SIGN_IDENTITY = "iPhone Developer"; 430 | INFOPLIST_FILE = NetworkSpeed/Info.plist; 431 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 432 | PRODUCT_BUNDLE_IDENTIFIER = com.ifandong.NetworkSpeed; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | }; 435 | name = Debug; 436 | }; 437 | A44BB65E1BB4F3AB00B290CC /* Release */ = { 438 | isa = XCBuildConfiguration; 439 | buildSettings = { 440 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 441 | CODE_SIGN_IDENTITY = "iPhone Developer"; 442 | INFOPLIST_FILE = NetworkSpeed/Info.plist; 443 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 444 | PRODUCT_BUNDLE_IDENTIFIER = com.ifandong.NetworkSpeed; 445 | PRODUCT_NAME = "$(TARGET_NAME)"; 446 | }; 447 | name = Release; 448 | }; 449 | A44BB6601BB4F3AB00B290CC /* Debug */ = { 450 | isa = XCBuildConfiguration; 451 | buildSettings = { 452 | BUNDLE_LOADER = "$(TEST_HOST)"; 453 | INFOPLIST_FILE = NetworkSpeedTests/Info.plist; 454 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 455 | PRODUCT_BUNDLE_IDENTIFIER = com.ifandong.NetworkSpeedTests; 456 | PRODUCT_NAME = "$(TARGET_NAME)"; 457 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/NetworkSpeed.app/NetworkSpeed"; 458 | }; 459 | name = Debug; 460 | }; 461 | A44BB6611BB4F3AB00B290CC /* Release */ = { 462 | isa = XCBuildConfiguration; 463 | buildSettings = { 464 | BUNDLE_LOADER = "$(TEST_HOST)"; 465 | INFOPLIST_FILE = NetworkSpeedTests/Info.plist; 466 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 467 | PRODUCT_BUNDLE_IDENTIFIER = com.ifandong.NetworkSpeedTests; 468 | PRODUCT_NAME = "$(TARGET_NAME)"; 469 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/NetworkSpeed.app/NetworkSpeed"; 470 | }; 471 | name = Release; 472 | }; 473 | A44BB6631BB4F3AB00B290CC /* Debug */ = { 474 | isa = XCBuildConfiguration; 475 | buildSettings = { 476 | INFOPLIST_FILE = NetworkSpeedUITests/Info.plist; 477 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 478 | PRODUCT_BUNDLE_IDENTIFIER = com.ifandong.NetworkSpeedUITests; 479 | PRODUCT_NAME = "$(TARGET_NAME)"; 480 | TEST_TARGET_NAME = NetworkSpeed; 481 | USES_XCTRUNNER = YES; 482 | }; 483 | name = Debug; 484 | }; 485 | A44BB6641BB4F3AB00B290CC /* Release */ = { 486 | isa = XCBuildConfiguration; 487 | buildSettings = { 488 | INFOPLIST_FILE = NetworkSpeedUITests/Info.plist; 489 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 490 | PRODUCT_BUNDLE_IDENTIFIER = com.ifandong.NetworkSpeedUITests; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | TEST_TARGET_NAME = NetworkSpeed; 493 | USES_XCTRUNNER = YES; 494 | }; 495 | name = Release; 496 | }; 497 | /* End XCBuildConfiguration section */ 498 | 499 | /* Begin XCConfigurationList section */ 500 | A44BB62A1BB4F3AB00B290CC /* Build configuration list for PBXProject "NetworkSpeed" */ = { 501 | isa = XCConfigurationList; 502 | buildConfigurations = ( 503 | A44BB65A1BB4F3AB00B290CC /* Debug */, 504 | A44BB65B1BB4F3AB00B290CC /* Release */, 505 | ); 506 | defaultConfigurationIsVisible = 0; 507 | defaultConfigurationName = Release; 508 | }; 509 | A44BB65C1BB4F3AB00B290CC /* Build configuration list for PBXNativeTarget "NetworkSpeed" */ = { 510 | isa = XCConfigurationList; 511 | buildConfigurations = ( 512 | A44BB65D1BB4F3AB00B290CC /* Debug */, 513 | A44BB65E1BB4F3AB00B290CC /* Release */, 514 | ); 515 | defaultConfigurationIsVisible = 0; 516 | defaultConfigurationName = Release; 517 | }; 518 | A44BB65F1BB4F3AB00B290CC /* Build configuration list for PBXNativeTarget "NetworkSpeedTests" */ = { 519 | isa = XCConfigurationList; 520 | buildConfigurations = ( 521 | A44BB6601BB4F3AB00B290CC /* Debug */, 522 | A44BB6611BB4F3AB00B290CC /* Release */, 523 | ); 524 | defaultConfigurationIsVisible = 0; 525 | defaultConfigurationName = Release; 526 | }; 527 | A44BB6621BB4F3AB00B290CC /* Build configuration list for PBXNativeTarget "NetworkSpeedUITests" */ = { 528 | isa = XCConfigurationList; 529 | buildConfigurations = ( 530 | A44BB6631BB4F3AB00B290CC /* Debug */, 531 | A44BB6641BB4F3AB00B290CC /* Release */, 532 | ); 533 | defaultConfigurationIsVisible = 0; 534 | defaultConfigurationName = Release; 535 | }; 536 | /* End XCConfigurationList section */ 537 | }; 538 | rootObject = A44BB6271BB4F3AB00B290CC /* Project object */; 539 | } 540 | -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/project.xcworkspace/xcuserdata/QingY-Mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iOSDeveloperTeam/NetworkSpeed/19b3be06cfbb51151ccffa5f21ed61195fe44fe3/NetworkSpeed.xcodeproj/project.xcworkspace/xcuserdata/QingY-Mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/project.xcworkspace/xcuserdata/iFD.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iOSDeveloperTeam/NetworkSpeed/19b3be06cfbb51151ccffa5f21ed61195fe44fe3/NetworkSpeed.xcodeproj/project.xcworkspace/xcuserdata/iFD.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/xcuserdata/QingY-Mac.xcuserdatad/xcschemes/NetworkSpeed.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/xcuserdata/QingY-Mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NetworkSpeed.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A44BB62E1BB4F3AB00B290CC 16 | 17 | primary 18 | 19 | 20 | A44BB6471BB4F3AB00B290CC 21 | 22 | primary 23 | 24 | 25 | A44BB6521BB4F3AB00B290CC 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/xcuserdata/iFD.xcuserdatad/xcschemes/NetworkSpeed.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /NetworkSpeed.xcodeproj/xcuserdata/iFD.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NetworkSpeed.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A44BB62E1BB4F3AB00B290CC 16 | 17 | primary 18 | 19 | 20 | A44BB6471BB4F3AB00B290CC 21 | 22 | primary 23 | 24 | 25 | A44BB6521BB4F3AB00B290CC 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /NetworkSpeed/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // NetworkSpeed 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /NetworkSpeed/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // NetworkSpeed 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /NetworkSpeed/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /NetworkSpeed/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NetworkSpeed/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /NetworkSpeed/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /NetworkSpeed/NetWorkSpeedMonitor.h: -------------------------------------------------------------------------------- 1 | // 2 | // NetWorkSpeedMonitor.h 3 | // NetworkSpeedMonitor 4 | // 5 | // Created by 范东 on 15/8/24. 6 | // Copyright (c) 2015年 ifandong.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef struct FDNetWorkBytes { 12 | long long int inBytes; 13 | long long int outBytes; 14 | }FDNetWorkBytes; 15 | 16 | @interface FDNetWorkSpeedMonitor : NSObject 17 | 18 | +(FDNetWorkSpeedMonitor *)sharedMonitor; 19 | 20 | @property (assign,nonatomic,readonly,getter=isMonitoring) BOOL monitoring; 21 | @property (assign,nonatomic,readonly) long long int bytesPerSecond; 22 | @property (assign,nonatomic,readonly) FDNetWorkBytes networkBytesPerSecond; 23 | 24 | @property (strong,nonatomic,readonly) NSString *speedStr; 25 | @property (strong,nonatomic,readonly) NSString *downloadStr; 26 | @property (strong,nonatomic,readonly) NSString *uploadStr; 27 | 28 | - (void)startMonitor; 29 | - (void)stopMonitor; 30 | @end 31 | -------------------------------------------------------------------------------- /NetworkSpeed/NetWorkSpeedMonitor.m: -------------------------------------------------------------------------------- 1 | // 2 | // NetWorkSpeedMonitor.m 3 | // NetworkSpeedMonitor 4 | // 5 | // Created by 范东 on 15/8/24. 6 | // Copyright (c) 2015年 ifandong.com. All rights reserved. 7 | // 8 | 9 | #import "NetWorkSpeedMonitor.h" 10 | #import "Reachability.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | @interface FDNetWorkSpeedMonitor () 17 | 18 | @property (assign,nonatomic) long long int bytesPerSecond; 19 | @property (assign,nonatomic) FDNetWorkBytes networkBytesPerSecond; 20 | //@property (strong,nonatomic) NSString *speedStr; 21 | 22 | @property (strong,nonatomic) NSTimer *timer; 23 | @property (strong,nonatomic) dispatch_source_t timerGCD; 24 | @property (assign,nonatomic) NSTimeInterval gapOfTimer; 25 | 26 | @property (assign,nonatomic) BOOL monitoring; 27 | 28 | @end 29 | 30 | @implementation FDNetWorkSpeedMonitor 31 | 32 | +(FDNetWorkSpeedMonitor *)sharedMonitor { 33 | static FDNetWorkSpeedMonitor *sharedMonitor = nil; 34 | static dispatch_once_t once; 35 | dispatch_once(&once, ^{ 36 | sharedMonitor = [[FDNetWorkSpeedMonitor alloc] init]; 37 | }); 38 | return sharedMonitor; 39 | } 40 | 41 | - (instancetype)init { 42 | if (self = [super init]) { 43 | self.gapOfTimer = 1.0; 44 | } 45 | return self; 46 | } 47 | 48 | #pragma mark - Custom Accessors 49 | 50 | - (void)setTimer:(NSTimer *)timer { 51 | if (_timer!=timer) { 52 | [_timer invalidate]; 53 | _timer = nil; 54 | } 55 | _timer = timer; 56 | } 57 | 58 | - (void)setTimerGCD:(dispatch_source_t)timerGCD { 59 | if (_timerGCD && _timerGCD!=timerGCD) { 60 | dispatch_cancel(self.timerGCD); 61 | _timerGCD = nil; 62 | } 63 | _timerGCD = timerGCD; 64 | } 65 | 66 | - (NSString *)speedStr { 67 | NSString *speedStr = [self bytesToSpeedStr:self.bytesPerSecond]; 68 | return speedStr; 69 | } 70 | 71 | - (NSString *)downloadStr { 72 | NSString *speedStr = [self bytesToSpeedStr:self.networkBytesPerSecond.inBytes]; 73 | return speedStr; 74 | } 75 | 76 | - (NSString *)uploadStr { 77 | NSString *speedStr = [self bytesToSpeedStr:self.networkBytesPerSecond.outBytes]; 78 | return speedStr; 79 | } 80 | 81 | #pragma mark - Pubic 82 | 83 | - (void)startMonitor { 84 | if (!self.isMonitoring) { 85 | __weak typeof(self) weakSelf = self; 86 | 87 | NSTimeInterval period = 1.0; //设置时间间隔 88 | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 89 | dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); 90 | dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行 91 | dispatch_source_set_event_handler(timer, ^{ 92 | //在这里执行事件 93 | [weakSelf monitorNetWorkSpeed]; 94 | }); 95 | dispatch_resume(timer); 96 | self.timerGCD = timer; 97 | self.monitoring = YES; 98 | } 99 | } 100 | 101 | - (void)stopMonitor { 102 | self.timerGCD = nil; 103 | self.monitoring = NO; 104 | } 105 | 106 | #pragma mark - Private 107 | 108 | - (void)monitorNetWorkSpeed { 109 | FDNetWorkBytes bytes = [self getBytes]; 110 | [self performSelector:@selector(reSetBtyesPersceond:) 111 | onThread:[NSThread mainThread] 112 | withObject:@{@"inBytes":@(bytes.inBytes),@"outBytes":@(bytes.outBytes)} 113 | waitUntilDone:YES]; 114 | } 115 | 116 | //获取每秒字节数 117 | -(FDNetWorkBytes)getBytes 118 | { 119 | static NSTimeInterval lastTime = 0; 120 | static FDNetWorkBytes lastNetworkBytes = {0,0}; 121 | static NetworkStatus lastStatus = NotReachable; 122 | 123 | FDNetWorkBytes currentNetworkBytes = {0,0}; 124 | 125 | Reachability *CurReach = [Reachability reachabilityForInternetConnection]; 126 | NetworkStatus currentStauts = [CurReach currentReachabilityStatus]; 127 | switch (currentStauts) { 128 | case NotReachable://没有网络 129 | { 130 | NSLog(@"noActiveNet"); 131 | break; 132 | } 133 | case ReachableViaWiFi://有wifi 134 | { 135 | currentNetworkBytes = [self getWifiBytes]; 136 | break; 137 | } 138 | case ReachableViaWWAN://有3G 139 | { 140 | currentNetworkBytes = [self getGprsBytes]; 141 | break; 142 | } 143 | default: 144 | break; 145 | } 146 | 147 | NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970]; 148 | NSTimeInterval duration = currentTime - lastTime; 149 | 150 | FDNetWorkBytes bytes = {0,0}; 151 | if (lastTime==0||duration==0||lastStatus!=currentStauts) { 152 | 153 | } else { 154 | bytes.outBytes = (currentNetworkBytes.outBytes - lastNetworkBytes.outBytes)/duration; 155 | bytes.inBytes = (currentNetworkBytes.inBytes - lastNetworkBytes.inBytes)/duration; 156 | } 157 | lastTime = currentTime; 158 | lastNetworkBytes = currentNetworkBytes; 159 | lastStatus = currentStauts; 160 | return bytes; 161 | } 162 | 163 | - (void)reSetBtyesPersceond:(NSDictionary *)bytesDic { 164 | FDNetWorkBytes bytes; 165 | bytes.inBytes = [[bytesDic objectForKey:@"inBytes"] longLongValue]; 166 | bytes.outBytes = [[bytesDic objectForKey:@"outBytes"] longLongValue]; 167 | self.networkBytesPerSecond = bytes; 168 | self.bytesPerSecond = _networkBytesPerSecond.inBytes + _networkBytesPerSecond.outBytes; 169 | } 170 | 171 | - (NSString *)bytesToSpeedStr:(long long int)bytes 172 | { 173 | if(bytes < 1024) // B 174 | { 175 | return [NSString stringWithFormat:@"%lldB/s", bytes]; 176 | } 177 | else if(bytes >= 1024 && bytes < 1024 * 1024) // KB 178 | { 179 | return [NSString stringWithFormat:@"%.1fKB/s", (double)bytes / 1024]; 180 | } 181 | else if(bytes >= 1024 * 1024 && bytes < 1024 * 1024 * 1024) // MB 182 | { 183 | return [NSString stringWithFormat:@"%.2fMB", (double)bytes / (1024 * 1024)]; 184 | } 185 | else // GB 186 | { 187 | return [NSString stringWithFormat:@"%.3fGB", (double)bytes / (1024 * 1024 * 1024)]; 188 | } 189 | } 190 | 191 | /** 192 | * 获取当前的Wifi流量 193 | * 194 | * @return 流量字节数 195 | */ 196 | - (FDNetWorkBytes)getWifiBytes 197 | { 198 | FDNetWorkBytes bytes = {0,0}; 199 | 200 | struct ifaddrs *ifa_list = 0, *ifa; 201 | if (getifaddrs(&ifa_list) == -1) { 202 | return bytes; 203 | } 204 | uint32_t iBytes = 0; 205 | uint32_t oBytes = 0; 206 | for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) { 207 | if (AF_LINK != ifa->ifa_addr->sa_family) 208 | continue; 209 | if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING)) 210 | continue; 211 | if (ifa->ifa_data == 0) 212 | continue; 213 | if (strncmp(ifa->ifa_name, "lo", 2)) { 214 | //lo表示是本地网卡即127.0.0.1 215 | //en0是Wifi网卡 216 | //pdp_ip0是2G/3G接入网卡 217 | struct if_data *if_data = (struct if_data *)ifa->ifa_data; 218 | iBytes += if_data->ifi_ibytes; 219 | oBytes += if_data->ifi_obytes; 220 | //NSLog(@"%s :iBytes is %d, oBytes is %d", ifa->ifa_name, iBytes, oBytes); 221 | } 222 | } 223 | freeifaddrs(ifa_list); 224 | bytes.inBytes = iBytes; 225 | bytes.outBytes = oBytes; 226 | return bytes; 227 | } 228 | 229 | /** 230 | * 获取当前的GPRS流量 231 | * 232 | * @return 流量字节数 233 | */ 234 | - (FDNetWorkBytes) getGprsBytes 235 | { 236 | FDNetWorkBytes bytes = {0,0}; 237 | 238 | struct ifaddrs *ifa_list= 0, *ifa; 239 | if (getifaddrs(&ifa_list)== -1) { 240 | return bytes; 241 | } 242 | uint32_t iBytes = 0; 243 | uint32_t oBytes = 0; 244 | for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) { 245 | if (AF_LINK != ifa->ifa_addr->sa_family) 246 | continue; 247 | if (!(ifa->ifa_flags& IFF_UP) &&!(ifa->ifa_flags & IFF_RUNNING)) 248 | continue; 249 | if (ifa->ifa_data == 0) 250 | continue; 251 | if (!strcmp(ifa->ifa_name,"pdp_ip0")) { 252 | //pdp_ip0是2G/3G接入网卡 253 | struct if_data *if_data = (struct if_data*)ifa->ifa_data; 254 | iBytes += if_data->ifi_ibytes; 255 | oBytes += if_data->ifi_obytes; 256 | //NSLog(@"%s :iBytes is %d, oBytes is %d",ifa->ifa_name, iBytes, oBytes); 257 | } 258 | } 259 | freeifaddrs(ifa_list); 260 | bytes.inBytes = iBytes; 261 | bytes.outBytes = oBytes; 262 | return bytes; 263 | } 264 | 265 | 266 | 267 | @end 268 | -------------------------------------------------------------------------------- /NetworkSpeed/Reachability.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: Reachability.h 3 | Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. 4 | Version: 3.5 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | #import 50 | #import 51 | 52 | 53 | typedef enum : NSInteger { 54 | NotReachable = 0, 55 | ReachableViaWiFi, 56 | ReachableViaWWAN 57 | } NetworkStatus; 58 | 59 | 60 | extern NSString *kReachabilityChangedNotification; 61 | 62 | 63 | @interface Reachability : NSObject 64 | 65 | /*! 66 | * Use to check the reachability of a given host name. 67 | */ 68 | + (instancetype)reachabilityWithHostName:(NSString *)hostName; 69 | 70 | /*! 71 | * Use to check the reachability of a given IP address. 72 | */ 73 | + (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress; 74 | 75 | /*! 76 | * Checks whether the default route is available. Should be used by applications that do not connect to a particular host. 77 | */ 78 | + (instancetype)reachabilityForInternetConnection; 79 | 80 | /*! 81 | * Checks whether a local WiFi connection is available. 82 | */ 83 | + (instancetype)reachabilityForLocalWiFi; 84 | 85 | /*! 86 | * Start listening for reachability notifications on the current run loop. 87 | */ 88 | - (BOOL)startNotifier; 89 | - (void)stopNotifier; 90 | 91 | - (NetworkStatus)currentReachabilityStatus; 92 | 93 | /*! 94 | * WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand. 95 | */ 96 | - (BOOL)connectionRequired; 97 | 98 | @end 99 | 100 | 101 | -------------------------------------------------------------------------------- /NetworkSpeed/Reachability.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: Reachability.m 3 | Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. 4 | Version: 3.5 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | #import 50 | #import 51 | #import 52 | 53 | #import 54 | 55 | #import "Reachability.h" 56 | 57 | 58 | NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification"; 59 | 60 | 61 | #pragma mark - Supporting functions 62 | 63 | #define kShouldPrintReachabilityFlags 0 64 | 65 | static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) 66 | { 67 | #if kShouldPrintReachabilityFlags 68 | 69 | NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n", 70 | (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', 71 | (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', 72 | 73 | (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', 74 | (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', 75 | (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', 76 | (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', 77 | (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', 78 | (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', 79 | (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-', 80 | comment 81 | ); 82 | #endif 83 | } 84 | 85 | 86 | static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) 87 | { 88 | #pragma unused (target, flags) 89 | NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); 90 | NSCAssert([(__bridge NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); 91 | 92 | Reachability* noteObject = (__bridge Reachability *)info; 93 | // Post a notification to notify the client that the network reachability changed. 94 | [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject]; 95 | } 96 | 97 | 98 | #pragma mark - Reachability implementation 99 | 100 | @implementation Reachability 101 | { 102 | BOOL _alwaysReturnLocalWiFiStatus; //default is NO 103 | SCNetworkReachabilityRef _reachabilityRef; 104 | } 105 | 106 | + (instancetype)reachabilityWithHostName:(NSString *)hostName 107 | { 108 | Reachability* returnValue = NULL; 109 | SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); 110 | if (reachability != NULL) 111 | { 112 | returnValue= [[self alloc] init]; 113 | if (returnValue != NULL) 114 | { 115 | returnValue->_reachabilityRef = reachability; 116 | returnValue->_alwaysReturnLocalWiFiStatus = NO; 117 | } 118 | } 119 | return returnValue; 120 | } 121 | 122 | 123 | + (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress 124 | { 125 | SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)hostAddress); 126 | 127 | Reachability* returnValue = NULL; 128 | 129 | if (reachability != NULL) 130 | { 131 | returnValue = [[self alloc] init]; 132 | if (returnValue != NULL) 133 | { 134 | returnValue->_reachabilityRef = reachability; 135 | returnValue->_alwaysReturnLocalWiFiStatus = NO; 136 | } 137 | } 138 | return returnValue; 139 | } 140 | 141 | 142 | 143 | + (instancetype)reachabilityForInternetConnection 144 | { 145 | struct sockaddr_in zeroAddress; 146 | bzero(&zeroAddress, sizeof(zeroAddress)); 147 | zeroAddress.sin_len = sizeof(zeroAddress); 148 | zeroAddress.sin_family = AF_INET; 149 | 150 | return [self reachabilityWithAddress:&zeroAddress]; 151 | } 152 | 153 | 154 | + (instancetype)reachabilityForLocalWiFi 155 | { 156 | struct sockaddr_in localWifiAddress; 157 | bzero(&localWifiAddress, sizeof(localWifiAddress)); 158 | localWifiAddress.sin_len = sizeof(localWifiAddress); 159 | localWifiAddress.sin_family = AF_INET; 160 | 161 | // IN_LINKLOCALNETNUM is defined in as 169.254.0.0. 162 | localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); 163 | 164 | Reachability* returnValue = [self reachabilityWithAddress: &localWifiAddress]; 165 | if (returnValue != NULL) 166 | { 167 | returnValue->_alwaysReturnLocalWiFiStatus = YES; 168 | } 169 | 170 | return returnValue; 171 | } 172 | 173 | 174 | #pragma mark - Start and stop notifier 175 | 176 | - (BOOL)startNotifier 177 | { 178 | BOOL returnValue = NO; 179 | SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; 180 | 181 | if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) 182 | { 183 | if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) 184 | { 185 | returnValue = YES; 186 | } 187 | } 188 | 189 | return returnValue; 190 | } 191 | 192 | 193 | - (void)stopNotifier 194 | { 195 | if (_reachabilityRef != NULL) 196 | { 197 | SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 198 | } 199 | } 200 | 201 | 202 | - (void)dealloc 203 | { 204 | [self stopNotifier]; 205 | if (_reachabilityRef != NULL) 206 | { 207 | CFRelease(_reachabilityRef); 208 | } 209 | } 210 | 211 | 212 | #pragma mark - Network Flag Handling 213 | 214 | - (NetworkStatus)localWiFiStatusForFlags:(SCNetworkReachabilityFlags)flags 215 | { 216 | PrintReachabilityFlags(flags, "localWiFiStatusForFlags"); 217 | NetworkStatus returnValue = NotReachable; 218 | 219 | if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) 220 | { 221 | returnValue = ReachableViaWiFi; 222 | } 223 | 224 | return returnValue; 225 | } 226 | 227 | 228 | - (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags 229 | { 230 | PrintReachabilityFlags(flags, "networkStatusForFlags"); 231 | if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) 232 | { 233 | // The target host is not reachable. 234 | return NotReachable; 235 | } 236 | 237 | NetworkStatus returnValue = NotReachable; 238 | 239 | if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) 240 | { 241 | /* 242 | If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi... 243 | */ 244 | returnValue = ReachableViaWiFi; 245 | } 246 | 247 | if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || 248 | (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) 249 | { 250 | /* 251 | ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs... 252 | */ 253 | 254 | if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) 255 | { 256 | /* 257 | ... and no [user] intervention is needed... 258 | */ 259 | returnValue = ReachableViaWiFi; 260 | } 261 | } 262 | 263 | if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) 264 | { 265 | /* 266 | ... but WWAN connections are OK if the calling application is using the CFNetwork APIs. 267 | */ 268 | returnValue = ReachableViaWWAN; 269 | } 270 | 271 | return returnValue; 272 | } 273 | 274 | 275 | - (BOOL)connectionRequired 276 | { 277 | NSAssert(_reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef"); 278 | SCNetworkReachabilityFlags flags; 279 | 280 | if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) 281 | { 282 | return (flags & kSCNetworkReachabilityFlagsConnectionRequired); 283 | } 284 | 285 | return NO; 286 | } 287 | 288 | 289 | - (NetworkStatus)currentReachabilityStatus 290 | { 291 | NSAssert(_reachabilityRef != NULL, @"currentNetworkStatus called with NULL SCNetworkReachabilityRef"); 292 | NetworkStatus returnValue = NotReachable; 293 | SCNetworkReachabilityFlags flags; 294 | 295 | if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags)) 296 | { 297 | if (_alwaysReturnLocalWiFiStatus) 298 | { 299 | returnValue = [self localWiFiStatusForFlags:flags]; 300 | } 301 | else 302 | { 303 | returnValue = [self networkStatusForFlags:flags]; 304 | } 305 | } 306 | 307 | return returnValue; 308 | } 309 | 310 | 311 | @end 312 | -------------------------------------------------------------------------------- /NetworkSpeed/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // NetworkSpeed 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /NetworkSpeed/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // NetworkSpeed 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "NetWorkSpeedMonitor.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet UILabel *speedLabel; 14 | 15 | @property (nonatomic, strong) FDNetWorkSpeedMonitor *speedMonitor; 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view, typically from a nib. 24 | self.speedMonitor = [FDNetWorkSpeedMonitor sharedMonitor]; 25 | [self.speedMonitor startMonitor]; 26 | } 27 | 28 | - (void)dealloc 29 | { 30 | [self.speedMonitor stopMonitor]; 31 | self.speedMonitor = nil; 32 | } 33 | 34 | - (void)setSpeedMonitor:(FDNetWorkSpeedMonitor *)speedMonitor 35 | { 36 | _speedMonitor = speedMonitor; 37 | if (_speedMonitor) { 38 | [_speedMonitor addObserver:self forKeyPath:@"bytesPerSecond" options:NSKeyValueObservingOptionNew context:nil]; 39 | [_speedMonitor addObserver:self forKeyPath:@"monitoring" options:NSKeyValueObservingOptionNew context:nil]; 40 | } 41 | } 42 | 43 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 44 | { 45 | if ([keyPath isEqualToString:@"bytesPerSecond"]) { 46 | NSLog(@"%@",[NSString stringWithFormat:@"\n 下载:%15s \n 上传:%15s \n 总计:%15s",[self.speedMonitor.downloadStr UTF8String],[self.speedMonitor.uploadStr UTF8String],[self.speedMonitor.speedStr UTF8String]]); 47 | self.speedLabel.text = [NSString stringWithFormat:@"%15s",[self.speedMonitor.downloadStr UTF8String]]; 48 | } 49 | } 50 | 51 | - (void)didReceiveMemoryWarning { 52 | [super didReceiveMemoryWarning]; 53 | // Dispose of any resources that can be recreated. 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /NetworkSpeed/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // NetworkSpeed 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /NetworkSpeedTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /NetworkSpeedTests/NetworkSpeedTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkSpeedTests.m 3 | // NetworkSpeedTests 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NetworkSpeedTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation NetworkSpeedTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /NetworkSpeedUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /NetworkSpeedUITests/NetworkSpeedUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkSpeedUITests.m 3 | // NetworkSpeedUITests 4 | // 5 | // Created by 范东 on 15/9/25. 6 | // Copyright © 2015年 ifandong. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NetworkSpeedUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation NetworkSpeedUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------