├── HFDownLoad.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── HFDownLoad.xccheckout └── xcuserdata │ └── yeaodong.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── HFDownLoad.xcscheme │ └── xcschememanagement.plist ├── HFDownLoad ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── HFConnection.h ├── HFConnection.m ├── HFSession.h ├── HFSession.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── pause.imageset │ │ ├── Contents.json │ │ └── pause.png │ └── start.imageset │ │ ├── Contents.json │ │ └── start.png ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── HFDownLoadTests ├── HFDownLoadTests.m └── Info.plist └── README.md /HFDownLoad.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C0BCDA681B9D21D200DFA53B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C0BCDA671B9D21D200DFA53B /* main.m */; }; 11 | C0BCDA6B1B9D21D200DFA53B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C0BCDA6A1B9D21D200DFA53B /* AppDelegate.m */; }; 12 | C0BCDA6E1B9D21D200DFA53B /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C0BCDA6D1B9D21D200DFA53B /* ViewController.m */; }; 13 | C0BCDA711B9D21D200DFA53B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C0BCDA6F1B9D21D200DFA53B /* Main.storyboard */; }; 14 | C0BCDA731B9D21D200DFA53B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C0BCDA721B9D21D200DFA53B /* Images.xcassets */; }; 15 | C0BCDA761B9D21D200DFA53B /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0BCDA741B9D21D200DFA53B /* LaunchScreen.xib */; }; 16 | C0BCDA821B9D21D200DFA53B /* HFDownLoadTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C0BCDA811B9D21D200DFA53B /* HFDownLoadTests.m */; }; 17 | C0BCDA901B9D34D900DFA53B /* HFConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = C0BCDA8F1B9D34D900DFA53B /* HFConnection.m */; }; 18 | C0BCDA931B9D367E00DFA53B /* HFSession.m in Sources */ = {isa = PBXBuildFile; fileRef = C0BCDA921B9D367E00DFA53B /* HFSession.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | C0BCDA7C1B9D21D200DFA53B /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = C0BCDA5A1B9D21D200DFA53B /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = C0BCDA611B9D21D200DFA53B; 27 | remoteInfo = HFDownLoad; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | C0BCDA621B9D21D200DFA53B /* HFDownLoad.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HFDownLoad.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | C0BCDA661B9D21D200DFA53B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | C0BCDA671B9D21D200DFA53B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | C0BCDA691B9D21D200DFA53B /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 36 | C0BCDA6A1B9D21D200DFA53B /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 37 | C0BCDA6C1B9D21D200DFA53B /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 38 | C0BCDA6D1B9D21D200DFA53B /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 39 | C0BCDA701B9D21D200DFA53B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 40 | C0BCDA721B9D21D200DFA53B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 41 | C0BCDA751B9D21D200DFA53B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 42 | C0BCDA7B1B9D21D200DFA53B /* HFDownLoadTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HFDownLoadTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | C0BCDA801B9D21D200DFA53B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | C0BCDA811B9D21D200DFA53B /* HFDownLoadTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HFDownLoadTests.m; sourceTree = ""; }; 45 | C0BCDA8E1B9D34D900DFA53B /* HFConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HFConnection.h; sourceTree = ""; }; 46 | C0BCDA8F1B9D34D900DFA53B /* HFConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HFConnection.m; sourceTree = ""; }; 47 | C0BCDA911B9D367E00DFA53B /* HFSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HFSession.h; sourceTree = ""; }; 48 | C0BCDA921B9D367E00DFA53B /* HFSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HFSession.m; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | C0BCDA5F1B9D21D200DFA53B /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | C0BCDA781B9D21D200DFA53B /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | C0BCDA591B9D21D200DFA53B = { 70 | isa = PBXGroup; 71 | children = ( 72 | C0BCDA641B9D21D200DFA53B /* HFDownLoad */, 73 | C0BCDA7E1B9D21D200DFA53B /* HFDownLoadTests */, 74 | C0BCDA631B9D21D200DFA53B /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | C0BCDA631B9D21D200DFA53B /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | C0BCDA621B9D21D200DFA53B /* HFDownLoad.app */, 82 | C0BCDA7B1B9D21D200DFA53B /* HFDownLoadTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | C0BCDA641B9D21D200DFA53B /* HFDownLoad */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | C0BCDA691B9D21D200DFA53B /* AppDelegate.h */, 91 | C0BCDA6A1B9D21D200DFA53B /* AppDelegate.m */, 92 | C0BCDA6C1B9D21D200DFA53B /* ViewController.h */, 93 | C0BCDA6D1B9D21D200DFA53B /* ViewController.m */, 94 | C0BCDA8E1B9D34D900DFA53B /* HFConnection.h */, 95 | C0BCDA8F1B9D34D900DFA53B /* HFConnection.m */, 96 | C0BCDA911B9D367E00DFA53B /* HFSession.h */, 97 | C0BCDA921B9D367E00DFA53B /* HFSession.m */, 98 | C0BCDA6F1B9D21D200DFA53B /* Main.storyboard */, 99 | C0BCDA721B9D21D200DFA53B /* Images.xcassets */, 100 | C0BCDA741B9D21D200DFA53B /* LaunchScreen.xib */, 101 | C0BCDA651B9D21D200DFA53B /* Supporting Files */, 102 | ); 103 | path = HFDownLoad; 104 | sourceTree = ""; 105 | }; 106 | C0BCDA651B9D21D200DFA53B /* Supporting Files */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | C0BCDA661B9D21D200DFA53B /* Info.plist */, 110 | C0BCDA671B9D21D200DFA53B /* main.m */, 111 | ); 112 | name = "Supporting Files"; 113 | sourceTree = ""; 114 | }; 115 | C0BCDA7E1B9D21D200DFA53B /* HFDownLoadTests */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | C0BCDA811B9D21D200DFA53B /* HFDownLoadTests.m */, 119 | C0BCDA7F1B9D21D200DFA53B /* Supporting Files */, 120 | ); 121 | path = HFDownLoadTests; 122 | sourceTree = ""; 123 | }; 124 | C0BCDA7F1B9D21D200DFA53B /* Supporting Files */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | C0BCDA801B9D21D200DFA53B /* Info.plist */, 128 | ); 129 | name = "Supporting Files"; 130 | sourceTree = ""; 131 | }; 132 | /* End PBXGroup section */ 133 | 134 | /* Begin PBXNativeTarget section */ 135 | C0BCDA611B9D21D200DFA53B /* HFDownLoad */ = { 136 | isa = PBXNativeTarget; 137 | buildConfigurationList = C0BCDA851B9D21D200DFA53B /* Build configuration list for PBXNativeTarget "HFDownLoad" */; 138 | buildPhases = ( 139 | C0BCDA5E1B9D21D200DFA53B /* Sources */, 140 | C0BCDA5F1B9D21D200DFA53B /* Frameworks */, 141 | C0BCDA601B9D21D200DFA53B /* Resources */, 142 | ); 143 | buildRules = ( 144 | ); 145 | dependencies = ( 146 | ); 147 | name = HFDownLoad; 148 | productName = HFDownLoad; 149 | productReference = C0BCDA621B9D21D200DFA53B /* HFDownLoad.app */; 150 | productType = "com.apple.product-type.application"; 151 | }; 152 | C0BCDA7A1B9D21D200DFA53B /* HFDownLoadTests */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = C0BCDA881B9D21D200DFA53B /* Build configuration list for PBXNativeTarget "HFDownLoadTests" */; 155 | buildPhases = ( 156 | C0BCDA771B9D21D200DFA53B /* Sources */, 157 | C0BCDA781B9D21D200DFA53B /* Frameworks */, 158 | C0BCDA791B9D21D200DFA53B /* Resources */, 159 | ); 160 | buildRules = ( 161 | ); 162 | dependencies = ( 163 | C0BCDA7D1B9D21D200DFA53B /* PBXTargetDependency */, 164 | ); 165 | name = HFDownLoadTests; 166 | productName = HFDownLoadTests; 167 | productReference = C0BCDA7B1B9D21D200DFA53B /* HFDownLoadTests.xctest */; 168 | productType = "com.apple.product-type.bundle.unit-test"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | C0BCDA5A1B9D21D200DFA53B /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | LastUpgradeCheck = 0710; 177 | ORGANIZATIONNAME = "洪峰"; 178 | TargetAttributes = { 179 | C0BCDA611B9D21D200DFA53B = { 180 | CreatedOnToolsVersion = 6.4; 181 | }; 182 | C0BCDA7A1B9D21D200DFA53B = { 183 | CreatedOnToolsVersion = 6.4; 184 | TestTargetID = C0BCDA611B9D21D200DFA53B; 185 | }; 186 | }; 187 | }; 188 | buildConfigurationList = C0BCDA5D1B9D21D200DFA53B /* Build configuration list for PBXProject "HFDownLoad" */; 189 | compatibilityVersion = "Xcode 3.2"; 190 | developmentRegion = English; 191 | hasScannedForEncodings = 0; 192 | knownRegions = ( 193 | en, 194 | Base, 195 | ); 196 | mainGroup = C0BCDA591B9D21D200DFA53B; 197 | productRefGroup = C0BCDA631B9D21D200DFA53B /* Products */; 198 | projectDirPath = ""; 199 | projectRoot = ""; 200 | targets = ( 201 | C0BCDA611B9D21D200DFA53B /* HFDownLoad */, 202 | C0BCDA7A1B9D21D200DFA53B /* HFDownLoadTests */, 203 | ); 204 | }; 205 | /* End PBXProject section */ 206 | 207 | /* Begin PBXResourcesBuildPhase section */ 208 | C0BCDA601B9D21D200DFA53B /* Resources */ = { 209 | isa = PBXResourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | C0BCDA711B9D21D200DFA53B /* Main.storyboard in Resources */, 213 | C0BCDA761B9D21D200DFA53B /* LaunchScreen.xib in Resources */, 214 | C0BCDA731B9D21D200DFA53B /* Images.xcassets in Resources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | C0BCDA791B9D21D200DFA53B /* Resources */ = { 219 | isa = PBXResourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | /* End PBXResourcesBuildPhase section */ 226 | 227 | /* Begin PBXSourcesBuildPhase section */ 228 | C0BCDA5E1B9D21D200DFA53B /* Sources */ = { 229 | isa = PBXSourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | C0BCDA6E1B9D21D200DFA53B /* ViewController.m in Sources */, 233 | C0BCDA6B1B9D21D200DFA53B /* AppDelegate.m in Sources */, 234 | C0BCDA681B9D21D200DFA53B /* main.m in Sources */, 235 | C0BCDA901B9D34D900DFA53B /* HFConnection.m in Sources */, 236 | C0BCDA931B9D367E00DFA53B /* HFSession.m in Sources */, 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | C0BCDA771B9D21D200DFA53B /* Sources */ = { 241 | isa = PBXSourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | C0BCDA821B9D21D200DFA53B /* HFDownLoadTests.m in Sources */, 245 | ); 246 | runOnlyForDeploymentPostprocessing = 0; 247 | }; 248 | /* End PBXSourcesBuildPhase section */ 249 | 250 | /* Begin PBXTargetDependency section */ 251 | C0BCDA7D1B9D21D200DFA53B /* PBXTargetDependency */ = { 252 | isa = PBXTargetDependency; 253 | target = C0BCDA611B9D21D200DFA53B /* HFDownLoad */; 254 | targetProxy = C0BCDA7C1B9D21D200DFA53B /* PBXContainerItemProxy */; 255 | }; 256 | /* End PBXTargetDependency section */ 257 | 258 | /* Begin PBXVariantGroup section */ 259 | C0BCDA6F1B9D21D200DFA53B /* Main.storyboard */ = { 260 | isa = PBXVariantGroup; 261 | children = ( 262 | C0BCDA701B9D21D200DFA53B /* Base */, 263 | ); 264 | name = Main.storyboard; 265 | sourceTree = ""; 266 | }; 267 | C0BCDA741B9D21D200DFA53B /* LaunchScreen.xib */ = { 268 | isa = PBXVariantGroup; 269 | children = ( 270 | C0BCDA751B9D21D200DFA53B /* Base */, 271 | ); 272 | name = LaunchScreen.xib; 273 | sourceTree = ""; 274 | }; 275 | /* End PBXVariantGroup section */ 276 | 277 | /* Begin XCBuildConfiguration section */ 278 | C0BCDA831B9D21D200DFA53B /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ALWAYS_SEARCH_USER_PATHS = NO; 282 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 283 | CLANG_CXX_LIBRARY = "libc++"; 284 | CLANG_ENABLE_MODULES = YES; 285 | CLANG_ENABLE_OBJC_ARC = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_CONSTANT_CONVERSION = YES; 288 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 289 | CLANG_WARN_EMPTY_BODY = YES; 290 | CLANG_WARN_ENUM_CONVERSION = YES; 291 | CLANG_WARN_INT_CONVERSION = YES; 292 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 293 | CLANG_WARN_UNREACHABLE_CODE = YES; 294 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 295 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 296 | COPY_PHASE_STRIP = NO; 297 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 298 | ENABLE_STRICT_OBJC_MSGSEND = YES; 299 | ENABLE_TESTABILITY = YES; 300 | GCC_C_LANGUAGE_STANDARD = gnu99; 301 | GCC_DYNAMIC_NO_PIC = NO; 302 | GCC_NO_COMMON_BLOCKS = YES; 303 | GCC_OPTIMIZATION_LEVEL = 0; 304 | GCC_PREPROCESSOR_DEFINITIONS = ( 305 | "DEBUG=1", 306 | "$(inherited)", 307 | ); 308 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 309 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 310 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 311 | GCC_WARN_UNDECLARED_SELECTOR = YES; 312 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 313 | GCC_WARN_UNUSED_FUNCTION = YES; 314 | GCC_WARN_UNUSED_VARIABLE = YES; 315 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 316 | MTL_ENABLE_DEBUG_INFO = YES; 317 | ONLY_ACTIVE_ARCH = YES; 318 | SDKROOT = iphoneos; 319 | TARGETED_DEVICE_FAMILY = "1,2"; 320 | }; 321 | name = Debug; 322 | }; 323 | C0BCDA841B9D21D200DFA53B /* Release */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ALWAYS_SEARCH_USER_PATHS = NO; 327 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 328 | CLANG_CXX_LIBRARY = "libc++"; 329 | CLANG_ENABLE_MODULES = YES; 330 | CLANG_ENABLE_OBJC_ARC = YES; 331 | CLANG_WARN_BOOL_CONVERSION = YES; 332 | CLANG_WARN_CONSTANT_CONVERSION = YES; 333 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 334 | CLANG_WARN_EMPTY_BODY = YES; 335 | CLANG_WARN_ENUM_CONVERSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 338 | CLANG_WARN_UNREACHABLE_CODE = YES; 339 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 340 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 341 | COPY_PHASE_STRIP = NO; 342 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 343 | ENABLE_NS_ASSERTIONS = NO; 344 | ENABLE_STRICT_OBJC_MSGSEND = YES; 345 | GCC_C_LANGUAGE_STANDARD = gnu99; 346 | GCC_NO_COMMON_BLOCKS = YES; 347 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 348 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 349 | GCC_WARN_UNDECLARED_SELECTOR = YES; 350 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 351 | GCC_WARN_UNUSED_FUNCTION = YES; 352 | GCC_WARN_UNUSED_VARIABLE = YES; 353 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 354 | MTL_ENABLE_DEBUG_INFO = NO; 355 | SDKROOT = iphoneos; 356 | TARGETED_DEVICE_FAMILY = "1,2"; 357 | VALIDATE_PRODUCT = YES; 358 | }; 359 | name = Release; 360 | }; 361 | C0BCDA861B9D21D200DFA53B /* Debug */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 365 | INFOPLIST_FILE = HFDownLoad/Info.plist; 366 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 367 | PRODUCT_BUNDLE_IDENTIFIER = "hongfeng.$(PRODUCT_NAME:rfc1034identifier)"; 368 | PRODUCT_NAME = "$(TARGET_NAME)"; 369 | }; 370 | name = Debug; 371 | }; 372 | C0BCDA871B9D21D200DFA53B /* Release */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 376 | INFOPLIST_FILE = HFDownLoad/Info.plist; 377 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 378 | PRODUCT_BUNDLE_IDENTIFIER = "hongfeng.$(PRODUCT_NAME:rfc1034identifier)"; 379 | PRODUCT_NAME = "$(TARGET_NAME)"; 380 | }; 381 | name = Release; 382 | }; 383 | C0BCDA891B9D21D200DFA53B /* Debug */ = { 384 | isa = XCBuildConfiguration; 385 | buildSettings = { 386 | BUNDLE_LOADER = "$(TEST_HOST)"; 387 | FRAMEWORK_SEARCH_PATHS = ( 388 | "$(SDKROOT)/Developer/Library/Frameworks", 389 | "$(inherited)", 390 | ); 391 | GCC_PREPROCESSOR_DEFINITIONS = ( 392 | "DEBUG=1", 393 | "$(inherited)", 394 | ); 395 | INFOPLIST_FILE = HFDownLoadTests/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 397 | PRODUCT_BUNDLE_IDENTIFIER = "hongfeng.$(PRODUCT_NAME:rfc1034identifier)"; 398 | PRODUCT_NAME = "$(TARGET_NAME)"; 399 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HFDownLoad.app/HFDownLoad"; 400 | }; 401 | name = Debug; 402 | }; 403 | C0BCDA8A1B9D21D200DFA53B /* Release */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | BUNDLE_LOADER = "$(TEST_HOST)"; 407 | FRAMEWORK_SEARCH_PATHS = ( 408 | "$(SDKROOT)/Developer/Library/Frameworks", 409 | "$(inherited)", 410 | ); 411 | INFOPLIST_FILE = HFDownLoadTests/Info.plist; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 413 | PRODUCT_BUNDLE_IDENTIFIER = "hongfeng.$(PRODUCT_NAME:rfc1034identifier)"; 414 | PRODUCT_NAME = "$(TARGET_NAME)"; 415 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HFDownLoad.app/HFDownLoad"; 416 | }; 417 | name = Release; 418 | }; 419 | /* End XCBuildConfiguration section */ 420 | 421 | /* Begin XCConfigurationList section */ 422 | C0BCDA5D1B9D21D200DFA53B /* Build configuration list for PBXProject "HFDownLoad" */ = { 423 | isa = XCConfigurationList; 424 | buildConfigurations = ( 425 | C0BCDA831B9D21D200DFA53B /* Debug */, 426 | C0BCDA841B9D21D200DFA53B /* Release */, 427 | ); 428 | defaultConfigurationIsVisible = 0; 429 | defaultConfigurationName = Release; 430 | }; 431 | C0BCDA851B9D21D200DFA53B /* Build configuration list for PBXNativeTarget "HFDownLoad" */ = { 432 | isa = XCConfigurationList; 433 | buildConfigurations = ( 434 | C0BCDA861B9D21D200DFA53B /* Debug */, 435 | C0BCDA871B9D21D200DFA53B /* Release */, 436 | ); 437 | defaultConfigurationIsVisible = 0; 438 | defaultConfigurationName = Release; 439 | }; 440 | C0BCDA881B9D21D200DFA53B /* Build configuration list for PBXNativeTarget "HFDownLoadTests" */ = { 441 | isa = XCConfigurationList; 442 | buildConfigurations = ( 443 | C0BCDA891B9D21D200DFA53B /* Debug */, 444 | C0BCDA8A1B9D21D200DFA53B /* Release */, 445 | ); 446 | defaultConfigurationIsVisible = 0; 447 | defaultConfigurationName = Release; 448 | }; 449 | /* End XCConfigurationList section */ 450 | }; 451 | rootObject = C0BCDA5A1B9D21D200DFA53B /* Project object */; 452 | } 453 | -------------------------------------------------------------------------------- /HFDownLoad.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HFDownLoad.xcodeproj/project.xcworkspace/xcshareddata/HFDownLoad.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 049AD015-56EC-4580-9FD0-9F2674C5E553 9 | IDESourceControlProjectName 10 | HFDownLoad 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 4889AFC4A24F2C97DBDC8F161587B5F0E6C66E15 14 | https://github.com/hongfenglt/HFDownLoad.git 15 | 16 | IDESourceControlProjectPath 17 | HFDownLoad.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 4889AFC4A24F2C97DBDC8F161587B5F0E6C66E15 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/hongfenglt/HFDownLoad.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 4889AFC4A24F2C97DBDC8F161587B5F0E6C66E15 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 4889AFC4A24F2C97DBDC8F161587B5F0E6C66E15 36 | IDESourceControlWCCName 37 | HFDownLoad 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /HFDownLoad.xcodeproj/xcuserdata/yeaodong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /HFDownLoad.xcodeproj/xcuserdata/yeaodong.xcuserdatad/xcschemes/HFDownLoad.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 | 67 | 68 | 78 | 80 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /HFDownLoad.xcodeproj/xcuserdata/yeaodong.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | HFDownLoad.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C0BCDA611B9D21D200DFA53B 16 | 17 | primary 18 | 19 | 20 | C0BCDA7A1B9D21D200DFA53B 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /HFDownLoad/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // HFDownLoad 4 | // 5 | // Created by 洪峰 on 15/9/7. 6 | // Copyright (c) 2015年 洪峰. 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 | -------------------------------------------------------------------------------- /HFDownLoad/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // HFDownLoad 4 | // 5 | // Created by 洪峰 on 15/9/7. 6 | // Copyright (c) 2015年 洪峰. 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 | -------------------------------------------------------------------------------- /HFDownLoad/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 | -------------------------------------------------------------------------------- /HFDownLoad/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 33 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 102 | 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 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 170 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /HFDownLoad/HFConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Created by 洪峰 on 15/9/7. 4 | * Copyright (c) 2015年 洪峰. All rights reserved. 5 | * 6 | * ##################################################### 7 | * # # 8 | * # _oo0oo_ # 9 | * # o8888888o # 10 | * # 88" . "88 # 11 | * # (| -_- |) # 12 | * # 0\ = /0 # 13 | * # ___/`---'\___ # 14 | * # .' \\| |# '. # 15 | * # / \\||| : |||# \ # 16 | * # / _||||| -:- |||||- \ # 17 | * # | | \\\ - #/ | | # 18 | * # | \_| ''\---/'' |_/ | # 19 | * # \ .-\__ '-' ___/-. / # 20 | * # ___'. .' /--.--\ `. .'___ # 21 | * # ."" '< `.___\_<|>_/___.' >' "". # 22 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | # 23 | * # \ \ `_. \_ __\ /__ _/ .-` / / # 24 | * # =====`-.____`.___ \_____/___.-`___.-'===== # 25 | * # `=---=' # 26 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 27 | * # # 28 | * # 佛祖保佑 永无BUG # 29 | * # # 30 | * ##################################################### 31 | * 32 | * 新浪微博:http://weibo.com/hongfenglt 33 | * 博客地址:http://blog.csdn.net/hongfengkt 34 | */ 35 | // HFDownLoad 36 | // HFConnection.h 37 | // 38 | 39 | #import 40 | 41 | @interface HFConnection : UIViewController 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /HFDownLoad/HFConnection.m: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Created by 洪峰 on 15/9/7. 4 | * Copyright (c) 2015年 洪峰. All rights reserved. 5 | * 6 | * 新浪微博:http://weibo.com/hongfenglt 7 | * 博客地址:http://blog.csdn.net/hongfengkt 8 | */ 9 | // HFDownLoad 10 | // HFConnection.m 11 | // 12 | 13 | #import "HFConnection.h" 14 | 15 | @interface HFConnection () 16 | 17 | @property (weak, nonatomic) IBOutlet UILabel *pgLabel; 18 | 19 | @property (weak, nonatomic) IBOutlet UIProgressView *myPregress; 20 | 21 | /** 22 | * 用来写数据的文件句柄对象 23 | */ 24 | @property (nonatomic, strong) NSFileHandle *writeHandle; 25 | 26 | /** 27 | * 文件的总长度 28 | */ 29 | @property (nonatomic, assign) long long totalLength; 30 | /** 31 | * 当前已经写入的总大小 32 | */ 33 | @property (nonatomic, assign) long long currentLength; 34 | /** 35 | * 连接对象 36 | */ 37 | @property (nonatomic, strong) NSURLConnection *connection; 38 | @end 39 | 40 | @implementation HFConnection 41 | 42 | - (void)viewDidLoad { 43 | [super viewDidLoad]; 44 | 45 | NSLog(@"sandbox:%@",NSHomeDirectory()); 46 | 47 | // [self download]; 48 | } 49 | 50 | - (void)download 51 | { 52 | // 创建URL 53 | // NSURL* url = [NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/10/25851/jdk-8u40-macosx-x64.1427945120.dmg"]; 54 | NSURL* url = [NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/9d/25765/sogou_mac_32c_V3.2.0.1437101586.dmg"]; 55 | // 创建请求 56 | NSURLRequest* request = [NSURLRequest requestWithURL:url]; 57 | // 发送请求去下载 (创建完conn对象后,会自动发起一个异步请求) 58 | [NSURLConnection connectionWithRequest:request delegate:self]; 59 | } 60 | 61 | 62 | #pragma mark - NSURLConnectionDataDelegate代理方法 63 | 64 | /** 65 | * 请求失败时调用(请求超时、网络异常) 66 | * 67 | * @param error 错误原因 68 | */ 69 | - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 70 | { 71 | 72 | } 73 | /** 74 | * 1.接收到服务器的响应就会调用 75 | * 76 | * @param response 响应 77 | */ 78 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 79 | { 80 | // 如果文件已经存在,不执行以下操作 81 | if (self.currentLength) return; 82 | // 文件路径 83 | NSString* ceches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; 84 | NSString* filepath = [ceches stringByAppendingPathComponent:response.suggestedFilename]; 85 | 86 | // 创建一个空的文件到沙盒中 87 | NSFileManager* mgr = [NSFileManager defaultManager]; 88 | [mgr createFileAtPath:filepath contents:nil attributes:nil]; 89 | 90 | // 创建一个用来写数据的文件句柄对象 91 | self.writeHandle = [NSFileHandle fileHandleForWritingAtPath:filepath]; 92 | 93 | // 获得文件的总大小 94 | self.totalLength = response.expectedContentLength; 95 | 96 | } 97 | /** 98 | * 2.当接收到服务器返回的实体数据时调用(具体内容,这个方法可能会被调用多次) 99 | * 100 | * @param data 这次返回的数据 101 | */ 102 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 103 | { 104 | // 移动到文件的最后面 105 | [self.writeHandle seekToEndOfFile]; 106 | 107 | // 将数据写入沙盒 108 | [self.writeHandle writeData:data]; 109 | 110 | // 累计写入文件的长度 111 | self.currentLength += data.length; 112 | 113 | // 下载进度 114 | self.myPregress.progress = (double)self.currentLength / self.totalLength; 115 | 116 | self.pgLabel.text = [NSString stringWithFormat:@"当前下载进度:%f",(double)self.currentLength / self.totalLength]; 117 | } 118 | /** 119 | * 3.加载完毕后调用(服务器的数据已经完全返回后) 120 | */ 121 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection 122 | { 123 | [[[UIAlertView alloc] initWithTitle:@"下载完成" message:@"已成功下载文件" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil] show]; 124 | 125 | 126 | 127 | self.currentLength = 0; 128 | self.totalLength = 0; 129 | 130 | // 关闭文件 131 | [self.writeHandle closeFile]; 132 | self.writeHandle = nil; 133 | } 134 | 135 | #pragma mark --按钮点击事件 136 | 137 | - (IBAction)btnClicked:(UIButton *)sender { 138 | 139 | // 状态取反 140 | sender.selected = !sender.isSelected; 141 | 142 | // 断点续传 143 | // 断点下载 144 | 145 | if (sender.selected) { // 继续(开始)下载 146 | // 1.URL 147 | // NSURL* url = [NSURL URLWithString:@"http://localhost:8080/shudai99/resources/The_Fixer.mp4"]; 148 | NSURL* url = [NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/9d/25765/sogou_mac_32c_V3.2.0.1437101586.dmg"]; 149 | // 2.请求 150 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 151 | 152 | // 设置请求头 153 | NSString *range = [NSString stringWithFormat:@"bytes=%lld-", self.currentLength]; 154 | [request setValue:range forHTTPHeaderField:@"Range"]; 155 | 156 | // 3.下载 157 | self.connection = [NSURLConnection connectionWithRequest:request delegate:self]; 158 | } else { // 暂停 159 | 160 | [self.connection cancel]; 161 | self.connection = nil; 162 | } 163 | } 164 | 165 | @end 166 | -------------------------------------------------------------------------------- /HFDownLoad/HFSession.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Created by 洪峰 on 15/9/7. 4 | * Copyright (c) 2015年 洪峰. All rights reserved. 5 | * 6 | * ##################################################### 7 | * # # 8 | * # _oo0oo_ # 9 | * # o8888888o # 10 | * # 88" . "88 # 11 | * # (| -_- |) # 12 | * # 0\ = /0 # 13 | * # ___/`---'\___ # 14 | * # .' \\| |# '. # 15 | * # / \\||| : |||# \ # 16 | * # / _||||| -:- |||||- \ # 17 | * # | | \\\ - #/ | | # 18 | * # | \_| ''\---/'' |_/ | # 19 | * # \ .-\__ '-' ___/-. / # 20 | * # ___'. .' /--.--\ `. .'___ # 21 | * # ."" '< `.___\_<|>_/___.' >' "". # 22 | * # | | : `- \`.;`\ _ /`;.`/ - ` : | | # 23 | * # \ \ `_. \_ __\ /__ _/ .-` / / # 24 | * # =====`-.____`.___ \_____/___.-`___.-'===== # 25 | * # `=---=' # 26 | * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 27 | * # # 28 | * # 佛祖保佑 永无BUG # 29 | * # # 30 | * ##################################################### 31 | * 32 | * 新浪微博:http://weibo.com/hongfenglt 33 | * 博客地址:http://blog.csdn.net/hongfengkt 34 | */ 35 | // HFDownLoad 36 | // HFSession.h 37 | // 38 | 39 | #import 40 | 41 | @interface HFSession : UIViewController 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /HFDownLoad/HFSession.m: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Created by 洪峰 on 15/9/7. 4 | * Copyright (c) 2015年 洪峰. All rights reserved. 5 | * 6 | * 新浪微博:http://weibo.com/hongfenglt 7 | * 博客地址:http://blog.csdn.net/hongfengkt 8 | */ 9 | // HFDownLoad 10 | // HFSession.m 11 | // 12 | 13 | #import "HFSession.h" 14 | 15 | @interface HFSession () 16 | 17 | @property (weak, nonatomic) IBOutlet UILabel *pgLabel; 18 | 19 | @property (weak, nonatomic) IBOutlet UIProgressView *myPregress; 20 | /** 21 | * 下载任务 22 | */ 23 | @property (nonatomic, strong) NSURLSessionDownloadTask* downloadTask; 24 | /** 25 | * resumeData记录下载位置 26 | */ 27 | @property (nonatomic, strong) NSData* resumeData; 28 | /** 29 | * session 30 | */ 31 | @property (nonatomic, strong) NSURLSession* session; 32 | 33 | @end 34 | 35 | @implementation HFSession 36 | /** 37 | * session的懒加载 38 | */ 39 | - (NSURLSession *)session 40 | { 41 | if (nil == _session) { 42 | 43 | NSURLSessionConfiguration *cfg = [NSURLSessionConfiguration defaultSessionConfiguration]; 44 | self.session = [NSURLSession sessionWithConfiguration:cfg delegate:self delegateQueue:[NSOperationQueue mainQueue]]; 45 | } 46 | return _session; 47 | } 48 | 49 | - (void)viewDidLoad { 50 | [super viewDidLoad]; 51 | // Do any additional setup after loading the view. 52 | 53 | } 54 | /** 55 | * 从0开始下载 56 | */ 57 | - (void)startDownload 58 | { 59 | #warning 使用我们自己服务器的地址执行断点下载没问题,但是百度软件的下载链接不成功,应该是百度服务器做了限制吧,或者我写的不完美,有想法欢迎交流 60 | // NSURL* url = [NSURL URLWithString:@"http://localhost:8080/shudai99/resources/The_Fixer.mp4"]; 61 | NSURL* url = [NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/9d/25765/sogou_mac_32c_V3.2.0.1437101586.dmg"]; 62 | 63 | // 创建任务 64 | self.downloadTask = [self.session downloadTaskWithURL:url]; 65 | 66 | // 开始任务 67 | [self.downloadTask resume]; 68 | } 69 | 70 | /** 71 | * 恢复下载 72 | */ 73 | 74 | - (void)resume 75 | { 76 | // 传入上次暂停下载返回的数据,就可以恢复下载 77 | self.downloadTask = [self.session downloadTaskWithResumeData:self.resumeData]; 78 | 79 | [self.downloadTask resume]; // 开始任务 80 | 81 | self.resumeData = nil; 82 | } 83 | 84 | /** 85 | * 暂停 86 | */ 87 | - (void)pause 88 | { 89 | __weak typeof(self) selfVc = self; 90 | [self.downloadTask cancelByProducingResumeData:^(NSData *resumeData) { 91 | // resumeData : 包含了继续下载的开始位置\下载的url 92 | selfVc.resumeData = resumeData; 93 | selfVc.downloadTask = nil; 94 | }]; 95 | } 96 | 97 | #pragma mark -- NSURLSessionDownloadDelegate 98 | /** 99 | * 下载完毕会调用 100 | * 101 | * @param location 文件临时地址 102 | */ 103 | - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask 104 | didFinishDownloadingToURL:(NSURL *)location 105 | { 106 | NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; 107 | // response.suggestedFilename : 建议使用的文件名,一般跟服务器端的文件名一致 108 | NSString *file = [caches stringByAppendingPathComponent:downloadTask.response.suggestedFilename]; 109 | 110 | // 将临时文件剪切或者复制Caches文件夹 111 | NSFileManager *mgr = [NSFileManager defaultManager]; 112 | 113 | // AtPath : 剪切前的文件路径 114 | // ToPath : 剪切后的文件路径 115 | [mgr moveItemAtPath:location.path toPath:file error:nil]; 116 | 117 | // 提示下载完成 118 | [[[UIAlertView alloc] initWithTitle:@"下载完成" message:downloadTask.response.suggestedFilename delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil] show]; 119 | } 120 | 121 | /** 122 | * 每次写入沙盒完毕调用 123 | * 在这里面监听下载进度,totalBytesWritten/totalBytesExpectedToWrite 124 | * 125 | * @param bytesWritten 这次写入的大小 126 | * @param totalBytesWritten 已经写入沙盒的大小 127 | * @param totalBytesExpectedToWrite 文件总大小 128 | */ 129 | - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask 130 | didWriteData:(int64_t)bytesWritten 131 | totalBytesWritten:(int64_t)totalBytesWritten 132 | totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite 133 | { 134 | self.myPregress.progress = (double)totalBytesWritten/totalBytesExpectedToWrite; 135 | self.pgLabel.text = [NSString stringWithFormat:@"下载进度:%f",(double)totalBytesWritten/totalBytesExpectedToWrite]; 136 | } 137 | 138 | /** 139 | * 恢复下载后调用, 140 | */ 141 | - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask 142 | didResumeAtOffset:(int64_t)fileOffset 143 | expectedTotalBytes:(int64_t)expectedTotalBytes 144 | { 145 | 146 | } 147 | 148 | #pragma mark --按钮点击事件 149 | 150 | - (IBAction)btnClicked:(UIButton *)sender { 151 | 152 | // 按钮状态取反 153 | sender.selected = !sender.isSelected; 154 | 155 | if (nil == self.downloadTask) { // 开始(继续)下载 156 | if (self.resumeData) { // 继续下载 157 | [self resume]; 158 | }else{ // 从0开始下载 159 | [self startDownload]; 160 | } 161 | 162 | }else{ // 暂停 163 | [self pause]; 164 | } 165 | 166 | } 167 | 168 | 169 | - (void)didReceiveMemoryWarning { 170 | [super didReceiveMemoryWarning]; 171 | // Dispose of any resources that can be recreated. 172 | } 173 | 174 | /** 175 | * Sesstion 简单执行下载 176 | */ 177 | - (void)SesstionDownLoad 178 | { 179 | NSURL* url = [NSURL URLWithString:@"http://dlsw.baidu.com/sw-search-sp/soft/9d/25765/sogou_mac_32c_V3.2.0.1437101586.dmg"]; 180 | 181 | // 得到session对象 182 | NSURLSession* session = [NSURLSession sharedSession]; 183 | 184 | // 创建任务 185 | NSURLSessionDownloadTask* downloadTask = [session downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { 186 | // location : 临时文件的路径(下载好的文件) 187 | 188 | NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; 189 | // response.suggestedFilename : 建议使用的文件名,一般跟服务器端的文件名一致 190 | NSString *file = [caches stringByAppendingPathComponent:response.suggestedFilename]; 191 | 192 | // 将临时文件剪切或者复制Caches文件夹 193 | NSFileManager *mgr = [NSFileManager defaultManager]; 194 | 195 | // AtPath : 剪切前的文件路径 196 | // ToPath : 剪切后的文件路径 197 | [mgr moveItemAtPath:location.path toPath:file error:nil]; 198 | }]; 199 | 200 | // 开始任务 201 | [downloadTask resume]; 202 | } 203 | 204 | /** 205 | * NSURLSession简单使用 206 | */ 207 | - (void)sessiondemo 208 | { 209 | // 1.得到session对象 210 | NSURLSession* session = [NSURLSession sharedSession]; 211 | NSURL* url = [NSURL URLWithString:@""]; 212 | 213 | // 2.创建一个task,任务 214 | NSURLSessionDataTask* dataTask = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 215 | // data 为返回数据 216 | }]; 217 | 218 | // 发送POST 219 | // [session dataTaskWithRequest:<#(NSURLRequest *)#> completionHandler:<#^(NSData *data, NSURLResponse *response, NSError *error)completionHandler#>] 220 | 221 | // 3.开始任务 222 | [dataTask resume]; 223 | } 224 | 225 | @end 226 | -------------------------------------------------------------------------------- /HFDownLoad/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 | "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 | } -------------------------------------------------------------------------------- /HFDownLoad/Images.xcassets/pause.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "pause.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /HFDownLoad/Images.xcassets/pause.imageset/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongfenglt/HFDownLoad/96a94a65598a61343d94fa13fd7059612b761fd4/HFDownLoad/Images.xcassets/pause.imageset/pause.png -------------------------------------------------------------------------------- /HFDownLoad/Images.xcassets/start.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "start.png" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /HFDownLoad/Images.xcassets/start.imageset/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongfenglt/HFDownLoad/96a94a65598a61343d94fa13fd7059612b761fd4/HFDownLoad/Images.xcassets/start.imageset/start.png -------------------------------------------------------------------------------- /HFDownLoad/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 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UISupportedInterfaceOrientations~ipad 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationPortraitUpsideDown 48 | UIInterfaceOrientationLandscapeLeft 49 | UIInterfaceOrientationLandscapeRight 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /HFDownLoad/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // HFDownLoad 4 | // 5 | // Created by 洪峰 on 15/9/7. 6 | // Copyright (c) 2015年 洪峰. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /HFDownLoad/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // HFDownLoad 4 | // 5 | // Created by 洪峰 on 15/9/7. 6 | // Copyright (c) 2015年 洪峰. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | @property (weak, nonatomic) IBOutlet UIImageView *imageView; 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | NSLog(@"sandbox:%@",NSHomeDirectory()); 21 | 22 | // 小文件下载方式 23 | // 1.NSData dataWithContentsOfURL 24 | // 2.NSURLConnection 25 | 26 | NSURL* url = [NSURL URLWithString:@"https://picjumbo.imgix.net/HNCK8461.jpg?q=40&w=1650&sharp=30"]; 27 | 28 | // [self downloadImageWithUrl:url]; 29 | [self downloadImage2WithUrl:url]; 30 | } 31 | 32 | /** 33 | * NSData dataWithContentsOfURL 下载文件 34 | */ 35 | - (void)downloadImageWithUrl:(NSURL *)url 36 | { 37 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 38 | 39 | // 其实是发送一个Get 请求 40 | NSData* data = [NSData dataWithContentsOfURL:url]; 41 | 42 | // 回到主线程刷新UI 43 | dispatch_async(dispatch_get_main_queue(), ^{ 44 | 45 | self.imageView.image = [UIImage imageWithData:data]; 46 | }); 47 | }); 48 | } 49 | 50 | /** 51 | * NSURLConnection 下载文件 52 | */ 53 | - (void)downloadImage2WithUrl:(NSURL *)url 54 | { 55 | [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 56 | 57 | self.imageView.image = [UIImage imageWithData:data]; 58 | }]; 59 | } 60 | 61 | - (void)didReceiveMemoryWarning { 62 | [super didReceiveMemoryWarning]; 63 | // Dispose of any resources that can be recreated. 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /HFDownLoad/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // HFDownLoad 4 | // 5 | // Created by 洪峰 on 15/9/7. 6 | // Copyright (c) 2015年 洪峰. 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 | -------------------------------------------------------------------------------- /HFDownLoadTests/HFDownLoadTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // HFDownLoadTests.m 3 | // HFDownLoadTests 4 | // 5 | // Created by 洪峰 on 15/9/7. 6 | // Copyright (c) 2015年 洪峰. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface HFDownLoadTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation HFDownLoadTests 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 | -------------------------------------------------------------------------------- /HFDownLoadTests/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HFDownloadDemo 2 | 3 | ![](http://img.blog.csdn.net/20150910174721232) 4 | 5 | 实例程序包含NSURLConnection 发请求、小文件下载、大文件下载、断点下载 6 | NSRULSession 发请求,小文件下载、大文件下载、断点下载等操作示例 7 | 8 | 关于两种下载方式具体的思路、区别见Blog:http://blog.csdn.net/hongfengkt/article/details/48290561 --------------------------------------------------------------------------------