├── NetworkDataStats.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── danny.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings └── xcuserdata │ └── danny.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── NetworkDataStats.xcscheme │ └── xcschememanagement.plist ├── NetworkDataStats ├── .gitignore ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Categories │ ├── NSURLConnection+Blocks.h │ └── NSURLConnection+Blocks.m ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── NetworkDataStats.xcdatamodeld │ ├── .xccurrentversion │ └── NetworkDataStats.xcdatamodel │ │ └── contents ├── Services │ ├── StatsGetter.h │ ├── StatsGetter.m │ ├── StatsManager.h │ ├── StatsManager.m │ ├── Storage.h │ └── Storage.m ├── ViewController.h ├── ViewController.m └── main.m ├── NetworkDataStatsTests ├── Info.plist └── NetworkDataStatsTests.m ├── README.md └── screenshot.png /NetworkDataStats.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 301FE74B1B062D6200737F0F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 301FE74A1B062D6200737F0F /* main.m */; }; 11 | 301FE74E1B062D6200737F0F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 301FE74D1B062D6200737F0F /* AppDelegate.m */; }; 12 | 301FE7541B062D6200737F0F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 301FE7531B062D6200737F0F /* ViewController.m */; }; 13 | 301FE7571B062D6200737F0F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 301FE7551B062D6200737F0F /* Main.storyboard */; }; 14 | 301FE7591B062D6200737F0F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 301FE7581B062D6200737F0F /* Images.xcassets */; }; 15 | 301FE75C1B062D6200737F0F /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 301FE75A1B062D6200737F0F /* LaunchScreen.xib */; }; 16 | 301FE7681B062D6200737F0F /* NetworkDataStatsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 301FE7671B062D6200737F0F /* NetworkDataStatsTests.m */; }; 17 | 301FE7731B062D8900737F0F /* StatsGetter.m in Sources */ = {isa = PBXBuildFile; fileRef = 301FE7721B062D8900737F0F /* StatsGetter.m */; }; 18 | 309336A91B06571600B7B693 /* StatsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 309336A81B06571600B7B693 /* StatsManager.m */; }; 19 | 309336AC1B06582100B7B693 /* Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = 309336AB1B06582000B7B693 /* Storage.m */; }; 20 | 309336B01B0747F400B7B693 /* NSURLConnection+Blocks.m in Sources */ = {isa = PBXBuildFile; fileRef = 309336AF1B0747F400B7B693 /* NSURLConnection+Blocks.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 301FE7621B062D6200737F0F /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 301FE73D1B062D6200737F0F /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 301FE7441B062D6200737F0F; 29 | remoteInfo = NetworkDataStats; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 301FE7451B062D6200737F0F /* NetworkDataStats.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetworkDataStats.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 301FE7491B062D6200737F0F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 36 | 301FE74A1B062D6200737F0F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 37 | 301FE74C1B062D6200737F0F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 38 | 301FE74D1B062D6200737F0F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 39 | 301FE7521B062D6200737F0F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 40 | 301FE7531B062D6200737F0F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 41 | 301FE7561B062D6200737F0F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 301FE7581B062D6200737F0F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 43 | 301FE75B1B062D6200737F0F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 44 | 301FE7611B062D6200737F0F /* NetworkDataStatsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NetworkDataStatsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 301FE7661B062D6200737F0F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | 301FE7671B062D6200737F0F /* NetworkDataStatsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NetworkDataStatsTests.m; sourceTree = ""; }; 47 | 301FE7711B062D8900737F0F /* StatsGetter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StatsGetter.h; path = Services/StatsGetter.h; sourceTree = ""; }; 48 | 301FE7721B062D8900737F0F /* StatsGetter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StatsGetter.m; path = Services/StatsGetter.m; sourceTree = ""; }; 49 | 309336A71B06571600B7B693 /* StatsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StatsManager.h; path = Services/StatsManager.h; sourceTree = ""; }; 50 | 309336A81B06571600B7B693 /* StatsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StatsManager.m; path = Services/StatsManager.m; sourceTree = ""; }; 51 | 309336AA1B06582000B7B693 /* Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Storage.h; path = Services/Storage.h; sourceTree = ""; }; 52 | 309336AB1B06582000B7B693 /* Storage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Storage.m; path = Services/Storage.m; sourceTree = ""; }; 53 | 309336AE1B0747F400B7B693 /* NSURLConnection+Blocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSURLConnection+Blocks.h"; path = "Categories/NSURLConnection+Blocks.h"; sourceTree = ""; }; 54 | 309336AF1B0747F400B7B693 /* NSURLConnection+Blocks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSURLConnection+Blocks.m"; path = "Categories/NSURLConnection+Blocks.m"; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 301FE7421B062D6200737F0F /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | 301FE75E1B062D6200737F0F /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXFrameworksBuildPhase section */ 73 | 74 | /* Begin PBXGroup section */ 75 | 301FE73C1B062D6200737F0F = { 76 | isa = PBXGroup; 77 | children = ( 78 | 301FE7471B062D6200737F0F /* NetworkDataStats */, 79 | 301FE7641B062D6200737F0F /* NetworkDataStatsTests */, 80 | 301FE7461B062D6200737F0F /* Products */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | 301FE7461B062D6200737F0F /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 301FE7451B062D6200737F0F /* NetworkDataStats.app */, 88 | 301FE7611B062D6200737F0F /* NetworkDataStatsTests.xctest */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | 301FE7471B062D6200737F0F /* NetworkDataStats */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 301FE74C1B062D6200737F0F /* AppDelegate.h */, 97 | 301FE74D1B062D6200737F0F /* AppDelegate.m */, 98 | 309336B11B0747F800B7B693 /* Categories */, 99 | 301FE7581B062D6200737F0F /* Images.xcassets */, 100 | 301FE75A1B062D6200737F0F /* LaunchScreen.xib */, 101 | 301FE7551B062D6200737F0F /* Main.storyboard */, 102 | 309336A61B0656FB00B7B693 /* Services */, 103 | 301FE7481B062D6200737F0F /* Supporting Files */, 104 | 301FE7521B062D6200737F0F /* ViewController.h */, 105 | 301FE7531B062D6200737F0F /* ViewController.m */, 106 | ); 107 | path = NetworkDataStats; 108 | sourceTree = ""; 109 | }; 110 | 301FE7481B062D6200737F0F /* Supporting Files */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 301FE7491B062D6200737F0F /* Info.plist */, 114 | 301FE74A1B062D6200737F0F /* main.m */, 115 | ); 116 | name = "Supporting Files"; 117 | sourceTree = ""; 118 | }; 119 | 301FE7641B062D6200737F0F /* NetworkDataStatsTests */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 301FE7671B062D6200737F0F /* NetworkDataStatsTests.m */, 123 | 301FE7651B062D6200737F0F /* Supporting Files */, 124 | ); 125 | path = NetworkDataStatsTests; 126 | sourceTree = ""; 127 | }; 128 | 301FE7651B062D6200737F0F /* Supporting Files */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 301FE7661B062D6200737F0F /* Info.plist */, 132 | ); 133 | name = "Supporting Files"; 134 | sourceTree = ""; 135 | }; 136 | 309336A61B0656FB00B7B693 /* Services */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 301FE7711B062D8900737F0F /* StatsGetter.h */, 140 | 301FE7721B062D8900737F0F /* StatsGetter.m */, 141 | 309336A71B06571600B7B693 /* StatsManager.h */, 142 | 309336A81B06571600B7B693 /* StatsManager.m */, 143 | 309336AA1B06582000B7B693 /* Storage.h */, 144 | 309336AB1B06582000B7B693 /* Storage.m */, 145 | ); 146 | name = Services; 147 | sourceTree = ""; 148 | }; 149 | 309336B11B0747F800B7B693 /* Categories */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | 309336AE1B0747F400B7B693 /* NSURLConnection+Blocks.h */, 153 | 309336AF1B0747F400B7B693 /* NSURLConnection+Blocks.m */, 154 | ); 155 | name = Categories; 156 | sourceTree = ""; 157 | }; 158 | /* End PBXGroup section */ 159 | 160 | /* Begin PBXNativeTarget section */ 161 | 301FE7441B062D6200737F0F /* NetworkDataStats */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = 301FE76B1B062D6200737F0F /* Build configuration list for PBXNativeTarget "NetworkDataStats" */; 164 | buildPhases = ( 165 | 301FE7411B062D6200737F0F /* Sources */, 166 | 301FE7421B062D6200737F0F /* Frameworks */, 167 | 301FE7431B062D6200737F0F /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | ); 173 | name = NetworkDataStats; 174 | productName = NetworkDataStats; 175 | productReference = 301FE7451B062D6200737F0F /* NetworkDataStats.app */; 176 | productType = "com.apple.product-type.application"; 177 | }; 178 | 301FE7601B062D6200737F0F /* NetworkDataStatsTests */ = { 179 | isa = PBXNativeTarget; 180 | buildConfigurationList = 301FE76E1B062D6200737F0F /* Build configuration list for PBXNativeTarget "NetworkDataStatsTests" */; 181 | buildPhases = ( 182 | 301FE75D1B062D6200737F0F /* Sources */, 183 | 301FE75E1B062D6200737F0F /* Frameworks */, 184 | 301FE75F1B062D6200737F0F /* Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | 301FE7631B062D6200737F0F /* PBXTargetDependency */, 190 | ); 191 | name = NetworkDataStatsTests; 192 | productName = NetworkDataStatsTests; 193 | productReference = 301FE7611B062D6200737F0F /* NetworkDataStatsTests.xctest */; 194 | productType = "com.apple.product-type.bundle.unit-test"; 195 | }; 196 | /* End PBXNativeTarget section */ 197 | 198 | /* Begin PBXProject section */ 199 | 301FE73D1B062D6200737F0F /* Project object */ = { 200 | isa = PBXProject; 201 | attributes = { 202 | LastUpgradeCheck = 0630; 203 | ORGANIZATIONNAME = omdan; 204 | TargetAttributes = { 205 | 301FE7441B062D6200737F0F = { 206 | CreatedOnToolsVersion = 6.3.1; 207 | SystemCapabilities = { 208 | com.apple.BackgroundModes = { 209 | enabled = 1; 210 | }; 211 | }; 212 | }; 213 | 301FE7601B062D6200737F0F = { 214 | CreatedOnToolsVersion = 6.3.1; 215 | TestTargetID = 301FE7441B062D6200737F0F; 216 | }; 217 | }; 218 | }; 219 | buildConfigurationList = 301FE7401B062D6200737F0F /* Build configuration list for PBXProject "NetworkDataStats" */; 220 | compatibilityVersion = "Xcode 3.2"; 221 | developmentRegion = English; 222 | hasScannedForEncodings = 0; 223 | knownRegions = ( 224 | en, 225 | Base, 226 | ); 227 | mainGroup = 301FE73C1B062D6200737F0F; 228 | productRefGroup = 301FE7461B062D6200737F0F /* Products */; 229 | projectDirPath = ""; 230 | projectRoot = ""; 231 | targets = ( 232 | 301FE7441B062D6200737F0F /* NetworkDataStats */, 233 | 301FE7601B062D6200737F0F /* NetworkDataStatsTests */, 234 | ); 235 | }; 236 | /* End PBXProject section */ 237 | 238 | /* Begin PBXResourcesBuildPhase section */ 239 | 301FE7431B062D6200737F0F /* Resources */ = { 240 | isa = PBXResourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | 301FE7571B062D6200737F0F /* Main.storyboard in Resources */, 244 | 301FE75C1B062D6200737F0F /* LaunchScreen.xib in Resources */, 245 | 301FE7591B062D6200737F0F /* Images.xcassets in Resources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | 301FE75F1B062D6200737F0F /* Resources */ = { 250 | isa = PBXResourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | /* End PBXResourcesBuildPhase section */ 257 | 258 | /* Begin PBXSourcesBuildPhase section */ 259 | 301FE7411B062D6200737F0F /* Sources */ = { 260 | isa = PBXSourcesBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | 301FE7731B062D8900737F0F /* StatsGetter.m in Sources */, 264 | 301FE74E1B062D6200737F0F /* AppDelegate.m in Sources */, 265 | 301FE74B1B062D6200737F0F /* main.m in Sources */, 266 | 301FE7541B062D6200737F0F /* ViewController.m in Sources */, 267 | 309336A91B06571600B7B693 /* StatsManager.m in Sources */, 268 | 309336B01B0747F400B7B693 /* NSURLConnection+Blocks.m in Sources */, 269 | 309336AC1B06582100B7B693 /* Storage.m in Sources */, 270 | ); 271 | runOnlyForDeploymentPostprocessing = 0; 272 | }; 273 | 301FE75D1B062D6200737F0F /* Sources */ = { 274 | isa = PBXSourcesBuildPhase; 275 | buildActionMask = 2147483647; 276 | files = ( 277 | 301FE7681B062D6200737F0F /* NetworkDataStatsTests.m in Sources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXSourcesBuildPhase section */ 282 | 283 | /* Begin PBXTargetDependency section */ 284 | 301FE7631B062D6200737F0F /* PBXTargetDependency */ = { 285 | isa = PBXTargetDependency; 286 | target = 301FE7441B062D6200737F0F /* NetworkDataStats */; 287 | targetProxy = 301FE7621B062D6200737F0F /* PBXContainerItemProxy */; 288 | }; 289 | /* End PBXTargetDependency section */ 290 | 291 | /* Begin PBXVariantGroup section */ 292 | 301FE7551B062D6200737F0F /* Main.storyboard */ = { 293 | isa = PBXVariantGroup; 294 | children = ( 295 | 301FE7561B062D6200737F0F /* Base */, 296 | ); 297 | name = Main.storyboard; 298 | sourceTree = ""; 299 | }; 300 | 301FE75A1B062D6200737F0F /* LaunchScreen.xib */ = { 301 | isa = PBXVariantGroup; 302 | children = ( 303 | 301FE75B1B062D6200737F0F /* Base */, 304 | ); 305 | name = LaunchScreen.xib; 306 | sourceTree = ""; 307 | }; 308 | /* End PBXVariantGroup section */ 309 | 310 | /* Begin XCBuildConfiguration section */ 311 | 301FE7691B062D6200737F0F /* Debug */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ALWAYS_SEARCH_USER_PATHS = NO; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_WARN_BOOL_CONVERSION = YES; 320 | CLANG_WARN_CONSTANT_CONVERSION = YES; 321 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 322 | CLANG_WARN_EMPTY_BODY = YES; 323 | CLANG_WARN_ENUM_CONVERSION = YES; 324 | CLANG_WARN_INT_CONVERSION = YES; 325 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 326 | CLANG_WARN_UNREACHABLE_CODE = YES; 327 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 328 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 329 | COPY_PHASE_STRIP = NO; 330 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 331 | ENABLE_STRICT_OBJC_MSGSEND = YES; 332 | GCC_C_LANGUAGE_STANDARD = gnu99; 333 | GCC_DYNAMIC_NO_PIC = NO; 334 | GCC_NO_COMMON_BLOCKS = YES; 335 | GCC_OPTIMIZATION_LEVEL = 0; 336 | GCC_PREPROCESSOR_DEFINITIONS = ( 337 | "DEBUG=1", 338 | "$(inherited)", 339 | ); 340 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 341 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 342 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 343 | GCC_WARN_UNDECLARED_SELECTOR = YES; 344 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 345 | GCC_WARN_UNUSED_FUNCTION = YES; 346 | GCC_WARN_UNUSED_VARIABLE = YES; 347 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 348 | MTL_ENABLE_DEBUG_INFO = YES; 349 | ONLY_ACTIVE_ARCH = YES; 350 | SDKROOT = iphoneos; 351 | }; 352 | name = Debug; 353 | }; 354 | 301FE76A1B062D6200737F0F /* Release */ = { 355 | isa = XCBuildConfiguration; 356 | buildSettings = { 357 | ALWAYS_SEARCH_USER_PATHS = NO; 358 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 359 | CLANG_CXX_LIBRARY = "libc++"; 360 | CLANG_ENABLE_MODULES = YES; 361 | CLANG_ENABLE_OBJC_ARC = YES; 362 | CLANG_WARN_BOOL_CONVERSION = YES; 363 | CLANG_WARN_CONSTANT_CONVERSION = YES; 364 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 365 | CLANG_WARN_EMPTY_BODY = YES; 366 | CLANG_WARN_ENUM_CONVERSION = YES; 367 | CLANG_WARN_INT_CONVERSION = YES; 368 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 369 | CLANG_WARN_UNREACHABLE_CODE = YES; 370 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 371 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 372 | COPY_PHASE_STRIP = NO; 373 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 374 | ENABLE_NS_ASSERTIONS = NO; 375 | ENABLE_STRICT_OBJC_MSGSEND = YES; 376 | GCC_C_LANGUAGE_STANDARD = gnu99; 377 | GCC_NO_COMMON_BLOCKS = YES; 378 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 379 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 380 | GCC_WARN_UNDECLARED_SELECTOR = YES; 381 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 382 | GCC_WARN_UNUSED_FUNCTION = YES; 383 | GCC_WARN_UNUSED_VARIABLE = YES; 384 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 385 | MTL_ENABLE_DEBUG_INFO = NO; 386 | SDKROOT = iphoneos; 387 | VALIDATE_PRODUCT = YES; 388 | }; 389 | name = Release; 390 | }; 391 | 301FE76C1B062D6200737F0F /* Debug */ = { 392 | isa = XCBuildConfiguration; 393 | buildSettings = { 394 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 395 | INFOPLIST_FILE = NetworkDataStats/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 397 | PRODUCT_NAME = "$(TARGET_NAME)"; 398 | }; 399 | name = Debug; 400 | }; 401 | 301FE76D1B062D6200737F0F /* Release */ = { 402 | isa = XCBuildConfiguration; 403 | buildSettings = { 404 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 405 | INFOPLIST_FILE = NetworkDataStats/Info.plist; 406 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 407 | PRODUCT_NAME = "$(TARGET_NAME)"; 408 | }; 409 | name = Release; 410 | }; 411 | 301FE76F1B062D6200737F0F /* Debug */ = { 412 | isa = XCBuildConfiguration; 413 | buildSettings = { 414 | BUNDLE_LOADER = "$(TEST_HOST)"; 415 | FRAMEWORK_SEARCH_PATHS = ( 416 | "$(SDKROOT)/Developer/Library/Frameworks", 417 | "$(inherited)", 418 | ); 419 | GCC_PREPROCESSOR_DEFINITIONS = ( 420 | "DEBUG=1", 421 | "$(inherited)", 422 | ); 423 | INFOPLIST_FILE = NetworkDataStatsTests/Info.plist; 424 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/NetworkDataStats.app/NetworkDataStats"; 427 | }; 428 | name = Debug; 429 | }; 430 | 301FE7701B062D6200737F0F /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | BUNDLE_LOADER = "$(TEST_HOST)"; 434 | FRAMEWORK_SEARCH_PATHS = ( 435 | "$(SDKROOT)/Developer/Library/Frameworks", 436 | "$(inherited)", 437 | ); 438 | INFOPLIST_FILE = NetworkDataStatsTests/Info.plist; 439 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 440 | PRODUCT_NAME = "$(TARGET_NAME)"; 441 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/NetworkDataStats.app/NetworkDataStats"; 442 | }; 443 | name = Release; 444 | }; 445 | /* End XCBuildConfiguration section */ 446 | 447 | /* Begin XCConfigurationList section */ 448 | 301FE7401B062D6200737F0F /* Build configuration list for PBXProject "NetworkDataStats" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | 301FE7691B062D6200737F0F /* Debug */, 452 | 301FE76A1B062D6200737F0F /* Release */, 453 | ); 454 | defaultConfigurationIsVisible = 0; 455 | defaultConfigurationName = Release; 456 | }; 457 | 301FE76B1B062D6200737F0F /* Build configuration list for PBXNativeTarget "NetworkDataStats" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | 301FE76C1B062D6200737F0F /* Debug */, 461 | 301FE76D1B062D6200737F0F /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | 301FE76E1B062D6200737F0F /* Build configuration list for PBXNativeTarget "NetworkDataStatsTests" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | 301FE76F1B062D6200737F0F /* Debug */, 470 | 301FE7701B062D6200737F0F /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | /* End XCConfigurationList section */ 476 | }; 477 | rootObject = 301FE73D1B062D6200737F0F /* Project object */; 478 | } 479 | -------------------------------------------------------------------------------- /NetworkDataStats.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NetworkDataStats.xcodeproj/project.xcworkspace/xcuserdata/danny.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dannyshmueli/NetworkUsage/ea4f9be7fba2141e0cc96f7c93f2326b0cc7d342/NetworkDataStats.xcodeproj/project.xcworkspace/xcuserdata/danny.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /NetworkDataStats.xcodeproj/project.xcworkspace/xcuserdata/danny.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /NetworkDataStats.xcodeproj/xcuserdata/danny.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /NetworkDataStats.xcodeproj/xcuserdata/danny.xcuserdatad/xcschemes/NetworkDataStats.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /NetworkDataStats.xcodeproj/xcuserdata/danny.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NetworkDataStats.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 301FE7441B062D6200737F0F 16 | 17 | primary 18 | 19 | 20 | 301FE7601B062D6200737F0F 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NetworkDataStats/.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /NetworkDataStats/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (strong, nonatomic) UIWindow *window; 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /NetworkDataStats/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "StatsManager.h" 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | 20 | [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; 21 | 22 | [StatsManager update]; 23 | 24 | return YES; 25 | } 26 | 27 | - (void)applicationWillResignActive:(UIApplication *)application { 28 | // 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. 29 | // 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. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application { 33 | // 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. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | // Saves changes in the application's managed object context before the application terminates. 48 | } 49 | 50 | #pragma mark - Background Fetch 51 | 52 | -(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 53 | { 54 | [StatsManager update]; 55 | completionHandler(UIBackgroundFetchResultNewData); 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /NetworkDataStats/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /NetworkDataStats/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 29 | 39 | 49 | 59 | 73 | 83 | 93 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /NetworkDataStats/Categories/NSURLConnection+Blocks.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURLRequest+NSURLRequest_Blocks.h 3 | // 4 | // Created by Rui Peres on 7/11/12. 5 | // 6 | 7 | #import 8 | 9 | typedef void(^CompletionBlock)(NSData *data, NSInteger statusCode); 10 | typedef void(^FailBlock)(NSError *error, NSInteger statusCode); 11 | 12 | typedef void(^CleanBlock)(); 13 | 14 | /** 15 | Instead of calling: 16 | 17 | [NSURLConnection connectionWithRequest:aRequest delegate:self]; 18 | 19 | You can call: 20 | 21 | [NSURLConnection connectionWithRequest:urlRequest onCompletion:^(NSData* data) 22 | { 23 | // Success case 24 | } onFail:^ (NSError *error){ 25 | // Fail case 26 | 27 | }]; 28 | **/ 29 | @interface NSURLConnection (NSURLConnection_Blocks) 30 | 31 | /** 32 | It will receive a request, a onCompletion block and a onFail block. One of them will be executed 33 | according to the request's response 34 | @param request a NSURLRequest 35 | @param completionBlock Block executed on success 36 | @param failBlock executed when the connection failed 37 | @return NSURLConnection* a pointer a NSURLConnection object 38 | */ 39 | +(NSURLConnection*)connectionWithRequest:(NSURLRequest*)request onCompletion:(CompletionBlock)completionBlock onFail:(FailBlock)failBlock; 40 | 41 | @end -------------------------------------------------------------------------------- /NetworkDataStats/Categories/NSURLConnection+Blocks.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURLRequest+NSURLRequest_Blocks.m 3 | // 4 | // Created by Rui Peres on 7/11/12. 5 | // 6 | 7 | #import "NSURLConnection+Blocks.h" 8 | 9 | @implementation NSURLConnection (NSURLConnection_Blocks) 10 | 11 | static CompletionBlock _completionBlock; 12 | static FailBlock _failBlock; 13 | static CleanBlock _cleanBlock; 14 | static NSMutableData *webData; 15 | static NSInteger responseCode; 16 | 17 | #pragma mark - Public Methods 18 | 19 | + (NSURLConnection*)connectionWithRequest:(NSURLRequest*)request onCompletion:(CompletionBlock)completionBlock onFail:(FailBlock)failBlock 20 | { 21 | _cleanBlock = [^{ 22 | _failBlock = nil; 23 | _completionBlock = nil; 24 | _cleanBlock = nil; 25 | webData = nil; 26 | } copy]; 27 | 28 | _completionBlock = nil; 29 | _failBlock = nil; 30 | 31 | _completionBlock = [completionBlock copy]; 32 | _failBlock = [failBlock copy]; 33 | 34 | NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:[self class]]; 35 | 36 | return connection; 37 | } 38 | 39 | #pragma mark - NSURLConnectionDelegate Implementation 40 | 41 | + (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 42 | { 43 | if (_failBlock) 44 | { 45 | _failBlock(error, responseCode); 46 | } 47 | 48 | if (_cleanBlock) 49 | { 50 | _cleanBlock(); 51 | } 52 | } 53 | 54 | + (void)connectionDidFinishLoading:(NSURLConnection *)connection 55 | { 56 | if (_completionBlock) 57 | { 58 | _completionBlock([NSData dataWithData:webData], responseCode); 59 | } 60 | 61 | if (_cleanBlock) 62 | { 63 | _cleanBlock(); 64 | } 65 | 66 | } 67 | 68 | + (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 69 | { 70 | NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 71 | responseCode = [httpResponse statusCode]; 72 | 73 | webData = [NSMutableData dataWithLength:1024]; 74 | [webData setLength: 0]; 75 | } 76 | 77 | + (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 78 | { 79 | [webData appendData:data]; 80 | } 81 | 82 | @end -------------------------------------------------------------------------------- /NetworkDataStats/Images.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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /NetworkDataStats/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.omdan.$(PRODUCT_NAME:rfc1034identifier) 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 | UIBackgroundModes 26 | 27 | fetch 28 | 29 | UILaunchStoryboardName 30 | LaunchScreen 31 | UIMainStoryboardFile 32 | Main 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /NetworkDataStats/NetworkDataStats.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /NetworkDataStats/NetworkDataStats.xcdatamodeld/NetworkDataStats.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /NetworkDataStats/Services/StatsGetter.h: -------------------------------------------------------------------------------- 1 | // 2 | // StatsGetter.h 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StatsGetter : NSObject 12 | 13 | /** 14 | * get the network stats for wifi and wan since last reboot. 15 | * 16 | * @return NSDictionary with network interfaces stats. 17 | */ 18 | +(NSDictionary *)getNetworkInterfacesCounters; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /NetworkDataStats/Services/StatsGetter.m: -------------------------------------------------------------------------------- 1 | // 2 | // StatsGetter.m 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import "StatsGetter.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | @implementation StatsGetter 16 | 17 | //names of interfaces: en0 is WiFi ,pdp_ip0 is WWAN 18 | 19 | //Search by prefix because there could be serveral internal interfaces i.e pdp_ip1. 20 | NSString *const kInterfacePrefixWifi = @"en"; 21 | NSString *const kInterfacePrefixWWan = @"pdp_ip"; 22 | 23 | 24 | // see example code: 25 | //http://stackoverflow.com/questions/7946699/iphone-data-usage-tracking-monitoring/8014012#8014012 26 | +(NSDictionary *)getNetworkInterfacesCounters 27 | { 28 | BOOL success; 29 | struct ifaddrs *addrs; 30 | const struct ifaddrs *cursor; 31 | const struct if_data *networkStatisc; 32 | 33 | NSInteger WiFiSent = 0; 34 | NSInteger WiFiReceived = 0; 35 | NSInteger WWANSent = 0; 36 | NSInteger WWANReceived = 0; 37 | 38 | success = getifaddrs(&addrs) == 0; 39 | if (success) 40 | { 41 | cursor = addrs; 42 | while (cursor != NULL) 43 | { 44 | NSString *name = [NSString stringWithFormat:@"%s",cursor->ifa_name]; 45 | if (cursor->ifa_addr->sa_family == AF_LINK) 46 | { 47 | NSLog(@"iinterface name: %@", name); 48 | if ([name hasPrefix:@"en"]) 49 | { 50 | networkStatisc = (const struct if_data *) cursor->ifa_data; 51 | WiFiSent+=networkStatisc->ifi_obytes; 52 | WiFiReceived+=networkStatisc->ifi_ibytes; 53 | } 54 | 55 | if ([name hasPrefix:@"pdp_ip"]) 56 | { 57 | networkStatisc = (const struct if_data *) cursor->ifa_data; 58 | WWANSent+=networkStatisc->ifi_obytes; 59 | WWANReceived+=networkStatisc->ifi_ibytes; 60 | } 61 | } 62 | 63 | cursor = cursor->ifa_next; 64 | } 65 | 66 | freeifaddrs(addrs); 67 | } 68 | 69 | return @{ 70 | @"wifiSent" : @(WiFiSent), 71 | @"wifiReceived" : @(WiFiReceived), 72 | @"WWanSent" : @(WWANSent), 73 | @"WWantReceived" : @(WWANReceived) 74 | }; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /NetworkDataStats/Services/StatsManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // StatsManager.h 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface StatsManager : NSObject 12 | 13 | +(void)update; 14 | +(void)reset; 15 | 16 | +(NSDictionary *)getStats; 17 | +(NSDate *)countingSince; 18 | +(NSDate *)lastRebootDate; 19 | 20 | 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /NetworkDataStats/Services/StatsManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // StatsManager.m 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import "StatsManager.h" 10 | #import "Storage.h" 11 | #import "StatsGetter.h" 12 | 13 | NSString *const kCountingSinceStorageKey = @"CountingSinceStorageKey"; 14 | NSString *const kLastRebootStorageKey = @"LastRebootStorageKey"; 15 | NSString *const kUsageOffsetStorageKey = @"DataOffsetStorageKey"; 16 | NSString *const kUsageStorageKey = @"UsageStorageKey"; 17 | 18 | // approx device boot time. 19 | double const kLastRebootDateCompareTollerance = 60; 20 | 21 | @implementation StatsManager 22 | 23 | #pragma mark - API 24 | 25 | +(void)update 26 | { 27 | if (![Storage getValueForKey:kLastRebootStorageKey])//first launch 28 | { 29 | [Storage storeValue:[self lastRebootDate] 30 | forKey:kLastRebootStorageKey]; 31 | [self storeCountingSinceAsNow]; 32 | //store fresh network usage 33 | [self storeFreshNetworkUsage]; 34 | } 35 | else //Not first launch 36 | { 37 | NSDate *storedLastRebootDate = [self storedLastRebootDate]; 38 | NSDate *deviceLastRebootDate = [self lastRebootDate]; 39 | if (fabs(deviceLastRebootDate.timeIntervalSince1970 - storedLastRebootDate.timeIntervalSince1970) < kLastRebootDateCompareTollerance) 40 | { 41 | //we can safely store fresh stats as it's the same reboot 42 | [self storeFreshNetworkUsage]; 43 | } 44 | else 45 | { 46 | [Storage storeValue:deviceLastRebootDate 47 | forKey:kLastRebootStorageKey]; 48 | 49 | //new reboot: need to accumalte stats 50 | NSDictionary *storedStats = [Storage getValueForKey:kUsageStorageKey]; 51 | NSDictionary *freshStats = [StatsGetter getNetworkInterfacesCounters]; 52 | 53 | storedStats = [self addOrSubtractStats:storedStats withStats:freshStats add:YES]; 54 | [Storage storeValue:storedStats forKey:kUsageStorageKey]; 55 | } 56 | } 57 | } 58 | 59 | +(void)reset 60 | { 61 | [self storeCountingSinceAsNow]; 62 | [Storage storeValue:[StatsGetter getNetworkInterfacesCounters] forKey:kUsageOffsetStorageKey]; 63 | [self storeFreshNetworkUsage]; 64 | } 65 | 66 | #pragma mark Getters 67 | 68 | +(NSDictionary *)getStats 69 | { 70 | NSDictionary *stats = [Storage getValueForKey:kUsageStorageKey]; 71 | 72 | NSDictionary *usageOffsetStats = [Storage getValueForKey:kUsageOffsetStorageKey]; 73 | 74 | if (usageOffsetStats) 75 | { 76 | stats = [self addOrSubtractStats:stats withStats:usageOffsetStats add:NO]; 77 | } 78 | return stats; 79 | } 80 | 81 | +(NSDate *)countingSince 82 | { 83 | return [Storage getValueForKey:kCountingSinceStorageKey]; 84 | } 85 | 86 | +(NSDate *)lastRebootDate 87 | { 88 | NSTimeInterval upTime = [NSProcessInfo processInfo].systemUptime; 89 | 90 | NSDate *now = [NSDate new]; 91 | return [now dateByAddingTimeInterval:-upTime]; 92 | } 93 | 94 | #pragma mark - Private 95 | 96 | +(void)storeCountingSinceAsNow 97 | { 98 | [Storage storeValue:[NSDate new] 99 | forKey:kCountingSinceStorageKey]; 100 | } 101 | 102 | 103 | +(void)storeFreshNetworkUsage 104 | { 105 | [Storage storeValue:[StatsGetter getNetworkInterfacesCounters] 106 | forKey:kUsageStorageKey]; 107 | } 108 | 109 | +(NSDate *)storedLastRebootDate 110 | { 111 | return [Storage getValueForKey:kLastRebootStorageKey]; 112 | } 113 | 114 | +(NSDictionary *)addOrSubtractStats:(NSDictionary *)stats withStats:(NSDictionary *)otherStats add:(BOOL)add 115 | { 116 | NSInteger sign = add ? 1 : -1; 117 | NSMutableDictionary *mutableStats = [[NSMutableDictionary alloc] initWithDictionary:stats]; 118 | for (NSString *statsKey in mutableStats.allKeys) 119 | { 120 | NSInteger one = [stats[statsKey] integerValue]; 121 | NSInteger two = [otherStats[statsKey] integerValue]; 122 | NSInteger result = one + (two *sign); 123 | 124 | mutableStats[statsKey] = @(result); 125 | } 126 | return mutableStats; 127 | } 128 | 129 | 130 | @end 131 | -------------------------------------------------------------------------------- /NetworkDataStats/Services/Storage.h: -------------------------------------------------------------------------------- 1 | // 2 | // Storage.h 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "Storage.h" 11 | 12 | @interface Storage : NSObject 13 | 14 | +(id)getValueForKey:(NSString *)key; 15 | 16 | +(void)storeValue:(id)value forKey:(NSString *)key; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /NetworkDataStats/Services/Storage.m: -------------------------------------------------------------------------------- 1 | // 2 | // Storage.m 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import "Storage.h" 10 | 11 | @implementation Storage 12 | 13 | +(id)getValueForKey:(NSString *)key 14 | { 15 | return [[NSUserDefaults standardUserDefaults] objectForKey:key]; 16 | } 17 | 18 | +(void)storeValue:(id)value forKey:(NSString *)key 19 | { 20 | if (value) 21 | { 22 | [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; 23 | } 24 | else 25 | { 26 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; 27 | } 28 | [[NSUserDefaults standardUserDefaults] synchronize]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /NetworkDataStats/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /NetworkDataStats/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "StatsManager.h" 11 | #import "NSURLConnection+Blocks.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (weak, nonatomic) IBOutlet UILabel *wifiSentLabel; 16 | @property (weak, nonatomic) IBOutlet UILabel *wifiReceivedLabel; 17 | @property (weak, nonatomic) IBOutlet UILabel *wanSentLabel; 18 | @property (weak, nonatomic) IBOutlet UILabel *wanReceivedLabel; 19 | 20 | @property (weak, nonatomic) IBOutlet UILabel *lastRebootLabel; 21 | @property (weak, nonatomic) IBOutlet UILabel *countingSinceLabel; 22 | 23 | @property (weak, nonatomic) IBOutlet UIButton *downloadSomethingButton; 24 | 25 | @end 26 | 27 | @implementation ViewController 28 | 29 | #pragma mark - Events 30 | 31 | - (IBAction)didPressResetButton:(id)sender 32 | { 33 | [StatsManager reset]; 34 | [self updateUi]; 35 | } 36 | 37 | - (IBAction)didPressDownloadSomethingButton:(id)sender 38 | { 39 | self.downloadSomethingButton.enabled = NO; 40 | 41 | NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://dannyshmueli.com/images/heroBack.jpg"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:300]; 42 | [NSURLConnection connectionWithRequest:req onCompletion:^(NSData *data, NSInteger statusCode ) 43 | { 44 | self.downloadSomethingButton.enabled = YES; 45 | } onFail:^(NSError *error, NSInteger statusCode) 46 | { 47 | self.downloadSomethingButton.enabled = YES; 48 | }]; 49 | } 50 | 51 | #pragma mark - Life Cycle 52 | 53 | - (void)viewDidLoad { 54 | [super viewDidLoad]; 55 | [self updateUi]; 56 | [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(refreshUI) userInfo:nil repeats:YES]; 57 | } 58 | 59 | - (void)didReceiveMemoryWarning { 60 | [super didReceiveMemoryWarning]; 61 | // Dispose of any resources that can be recreated. 62 | } 63 | 64 | #pragma mark - Private 65 | -(void)refreshUI 66 | { 67 | [StatsManager update]; 68 | [self updateUi]; 69 | } 70 | 71 | -(NSString *)formatBytesToString:(NSNumber *)sizeInBytes 72 | { 73 | float sizeInKBytes = sizeInBytes.integerValue / 1000; 74 | if ((NSInteger)sizeInKBytes / 1000 == 0) 75 | { 76 | return [NSString stringWithFormat:@"%.0f KBytes", @(sizeInKBytes).floatValue]; 77 | }else 78 | { 79 | return [NSString stringWithFormat:@"%.2f MBytes", @(sizeInKBytes/1000).floatValue]; 80 | } 81 | } 82 | 83 | -(void)updateUi 84 | { 85 | NSDictionary *stats = [StatsManager getStats]; 86 | self.wifiSentLabel.text = [NSString stringWithFormat:@"Wifi Sent: %@", [self formatBytesToString:stats[@"wifiSent"]]]; 87 | self.wifiReceivedLabel.text = [NSString stringWithFormat:@"Wifi Received: %@",[ self formatBytesToString:stats[@"wifiReceived"]]]; 88 | 89 | self.wanSentLabel.text = [NSString stringWithFormat:@"3G Sent: %@", [self formatBytesToString:stats[@"WWanSent"]]]; 90 | self.wanReceivedLabel.text = [NSString stringWithFormat:@"3G Received: %@", [self formatBytesToString:stats[@"WWantReceived"]]]; 91 | 92 | self.lastRebootLabel.text = [NSString stringWithFormat:@"Last Reboot: %@", [StatsManager lastRebootDate]]; 93 | self.countingSinceLabel.text = [NSString stringWithFormat:@"Counting Since: %@", [StatsManager countingSince]]; 94 | } 95 | 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /NetworkDataStats/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // NetworkDataStats 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. 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 | -------------------------------------------------------------------------------- /NetworkDataStatsTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.omdan.$(PRODUCT_NAME:rfc1034identifier) 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 | -------------------------------------------------------------------------------- /NetworkDataStatsTests/NetworkDataStatsTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkDataStatsTests.m 3 | // NetworkDataStatsTests 4 | // 5 | // Created by Danny Shmueli on 5/15/15. 6 | // Copyright (c) 2015 omdan. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NetworkDataStatsTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation NetworkDataStatsTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetworkUsage 2 | iOS Network Usage Meter proof of concept. 3 | 4 | 5 | ###How: 6 | * By investigating the iOS network interfaces using [getifaddrs](http://man7.org/linux/man-pages/man3/getifaddrs.3.html) method. We are able to get the incoming and outgoing bytes for each network interface since last reboot. 7 | * To get the last reboot: 8 | ```ObjC 9 | [NSProcessInfo processInfo].systemUptime; 10 | ``` 11 | 12 | ###What: 13 | * On app launch updates the stats. 14 | * Uses periodic background fetch to update the results as often as possible. 15 | * Does not loose stats because of reboots. 16 | * "Reset" button: resets counting stats (saves current stats as offset). 17 | * "Download Something": downloads a 2mb file from the internet. 18 | 19 | ###Caveats: 20 | Using the background fetch to make sure the stats are updated can cause incorrect stats in extreme cases: according to Apple Docs when registering for background fetch - which wakes up the app to do some actions: 21 | ```ObjC 22 | - (void)setMinimumBackgroundFetchInterval:(NSTimeInterval)minimumBackgroundFetchInterval 23 | ``` 24 | > The minimum number of seconds that must elapse before another background fetch can be initiated. This value is **advisory only and does not indicate the exact amount of time expected between fetch operations.** 25 | > [See Apple Doc](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/setMinimumBackgroundFetchInterval:) 26 | 27 | We set this value to `UIApplicationBackgroundFetchIntervalMinimum` to update as often as the system allows. This sounds vague and therefore there might be a case where the user: 28 | (a) Reboots the device. (b) Does many network consuming actions. 29 | (c) Reboots again. 30 | And all the while our background fetch action is not called. 31 | 32 | To overcome such scenario we could replace the background fetch with remote notification mechanism. 33 | 34 | ###Attributions: 35 | * [Stackoverflow answer](http://stackoverflow.com/questions/7946699/iphone-data-usage-tracking-monitoring/8014012#8014012) for getting the network interfaces stats. 36 | * Background fetch info: http://possiblemobile.com/2013/09/ios-7-background-fetch/ 37 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dannyshmueli/NetworkUsage/ea4f9be7fba2141e0cc96f7c93f2326b0cc7d342/screenshot.png --------------------------------------------------------------------------------