File tree Expand file tree Collapse file tree
project.xcworkspace/xcuserdata/ad.xcuserdatad
Assets.xcassets/AppIcon.appiconset Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+ <!--
4+ .xcodeSampleCode.plist
5+ RegularExpression
6+
7+ Created by ad on 25/12/2017.
8+ Copyright (c) 2017 ___ORGANIZATIONNAME___. All rights reserved.
9+ -->
10+ <plist version =" 1.0" >
11+ <dict >
12+
13+ </dict >
14+ </plist >
Original file line number Diff line number Diff line change 2727/* End PBXContainerItemProxy section */
2828
2929/* Begin PBXFileReference section */
30+ 6016A8CA1FF93EEA006A1F16 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
3031 609126F51E30E86600679292 /* NSURLSession1.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NSURLSession1.app; sourceTree = BUILT_PRODUCTS_DIR; };
3132 609126F91E30E86600679292 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3233 609126FB1E30E86600679292 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
6364 609126EC1E30E86600679292 = {
6465 isa = PBXGroup;
6566 children = (
67+ 6016A8CA1FF93EEA006A1F16 /* README.md */,
6668 609126F71E30E86600679292 /* NSURLSession1 */,
6769 609127111E30E86600679292 /* NSURLSession1Tests */,
6870 609126F61E30E86600679292 /* Products */,
411413 609127191E30E86600679292 /* Release */,
412414 );
413415 defaultConfigurationIsVisible = 0;
416+ defaultConfigurationName = Release;
414417 };
415418 6091271A1E30E86600679292 /* Build configuration list for PBXNativeTarget "NSURLSession1Tests" */ = {
416419 isa = XCConfigurationList;
419422 6091271C1E30E86600679292 /* Release */,
420423 );
421424 defaultConfigurationIsVisible = 0;
425+ defaultConfigurationName = Release;
422426 };
423427/* End XCConfigurationList section */
424428 };
Original file line number Diff line number Diff line change 11{
22 "images" : [
3+ {
4+ "idiom" : " iphone" ,
5+ "size" : " 20x20" ,
6+ "scale" : " 2x"
7+ },
8+ {
9+ "idiom" : " iphone" ,
10+ "size" : " 20x20" ,
11+ "scale" : " 3x"
12+ },
313 {
414 "idiom" : " iphone" ,
515 "size" : " 29x29" ,
3040 "size" : " 60x60" ,
3141 "scale" : " 3x"
3242 },
43+ {
44+ "idiom" : " ipad" ,
45+ "size" : " 20x20" ,
46+ "scale" : " 1x"
47+ },
48+ {
49+ "idiom" : " ipad" ,
50+ "size" : " 20x20" ,
51+ "scale" : " 2x"
52+ },
3353 {
3454 "idiom" : " ipad" ,
3555 "size" : " 29x29" ,
5979 "idiom" : " ipad" ,
6080 "size" : " 76x76" ,
6181 "scale" : " 2x"
82+ },
83+ {
84+ "idiom" : " ipad" ,
85+ "size" : " 83.5x83.5" ,
86+ "scale" : " 2x"
87+ },
88+ {
89+ "idiom" : " ios-marketing" ,
90+ "size" : " 1024x1024" ,
91+ "scale" : " 1x"
6292 }
6393 ],
6494 "info" : {
Original file line number Diff line number Diff line change @@ -53,6 +53,12 @@ - (void)viewDidLoad
5353 [self .downloadTask resume ];
5454}
5555
56+ - (void )dealloc {
57+ // 移除观察者。
58+ [self removeObserver: self forKeyPath: @" resumeData" ];
59+ [self removeObserver: self forKeyPath: @" downloadTask" ];
60+ }
61+
5662#pragma mark Getters & Setters
5763- (NSURLSession *)session
5864{
@@ -148,12 +154,16 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
148154 dispatch_async (dispatch_get_main_queue (), ^{
149155 self.resumeButton .hidden = (self.resumeData == nil );
150156 });
151- } else if ([keyPath isEqualToString: @" downloadTask" ])
157+ }
158+ else if ([keyPath isEqualToString: @" downloadTask" ])
152159 {
153160 dispatch_async (dispatch_get_main_queue (), ^{
154161 self.cancelButton .hidden = (self.downloadTask == nil );
155162 });
156163 }
164+ else
165+ // 如果遇到没有观察的属性,将其交由父类处理,父类可能也在观察该属性。
166+ [super observeValueForKeyPath: keyPath ofObject: object change: change context: context];
157167}
158168
159169@end
Original file line number Diff line number Diff line change 1+ ### NSURLSession的使用
2+
3+ ` NSURLSession ` 提供了一个可供通过网络下载内容的API,并且具有丰富的代理方法。在iOS中,` NSURLSession ` 支持在app未运行或挂起时进行后台下载。此外,` NSURLSession ` 原生的支持data、file、ftp、http和https URL方案,以及用户首选项中代理和socks网关。
4+
5+ 这篇文章通过下载、暂停、恢复下载图片来学习` NSURLSession ` 。详细介绍查看下面文章:
6+
7+ < https://github.com/pro648/tips/wiki/NSURLSession的使用(一) >
You can’t perform that action at this time.
0 commit comments