├── .gitignore
├── MKWebSocket.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ └── IDEWorkspaceChecks.plist
├── MKWebSocket.xcworkspace
├── contents.xcworkspacedata
└── xcshareddata
│ └── IDEWorkspaceChecks.plist
├── MKWebSocket
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ ├── AccentColor.colorset
│ │ └── Contents.json
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ └── Contents.json
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Catogery
│ ├── NSDate+Additions.h
│ ├── NSDate+Additions.m
│ ├── NSObject+Additions.h
│ └── NSObject+Additions.m
├── GCDObjc
│ ├── GCDConstant.h
│ ├── GCDSemaphore.h
│ ├── GCDSemaphore.m
│ ├── GCDSource.h
│ └── GCDSource.m
├── Info.plist
├── MKTestModule.h
├── MKTestModule.m
├── MKWSPingVC.h
├── MKWSPingVC.m
├── ViewController.h
├── ViewController.m
├── ViewController.xib
├── WebSocket
│ ├── MKWMesssagePackage.h
│ ├── MKWMesssagePackage.m
│ ├── MKWebSocketBaseModule.h
│ ├── MKWebSocketBaseModule.m
│ ├── MKWebSocketClient.h
│ ├── MKWebSocketClient.m
│ ├── MKWebSocketMessage.h
│ ├── MKWebSocketMessage.m
│ ├── MKWebSocktDelegate.h
│ └── MKWebSocktDelegate.m
└── main.m
├── Podfile
├── Podfile.lock
├── Pods
├── AFNetworking
│ ├── AFNetworking
│ │ ├── AFCompatibilityMacros.h
│ │ ├── AFHTTPSessionManager.h
│ │ ├── AFHTTPSessionManager.m
│ │ ├── AFNetworkReachabilityManager.h
│ │ ├── AFNetworkReachabilityManager.m
│ │ ├── AFNetworking.h
│ │ ├── AFSecurityPolicy.h
│ │ ├── AFSecurityPolicy.m
│ │ ├── AFURLRequestSerialization.h
│ │ ├── AFURLRequestSerialization.m
│ │ ├── AFURLResponseSerialization.h
│ │ ├── AFURLResponseSerialization.m
│ │ ├── AFURLSessionManager.h
│ │ └── AFURLSessionManager.m
│ ├── LICENSE
│ ├── README.md
│ └── UIKit+AFNetworking
│ │ ├── AFAutoPurgingImageCache.h
│ │ ├── AFAutoPurgingImageCache.m
│ │ ├── AFImageDownloader.h
│ │ ├── AFImageDownloader.m
│ │ ├── AFNetworkActivityIndicatorManager.h
│ │ ├── AFNetworkActivityIndicatorManager.m
│ │ ├── UIActivityIndicatorView+AFNetworking.h
│ │ ├── UIActivityIndicatorView+AFNetworking.m
│ │ ├── UIButton+AFNetworking.h
│ │ ├── UIButton+AFNetworking.m
│ │ ├── UIImageView+AFNetworking.h
│ │ ├── UIImageView+AFNetworking.m
│ │ ├── UIKit+AFNetworking.h
│ │ ├── UIProgressView+AFNetworking.h
│ │ ├── UIProgressView+AFNetworking.m
│ │ ├── UIRefreshControl+AFNetworking.h
│ │ ├── UIRefreshControl+AFNetworking.m
│ │ ├── WKWebView+AFNetworking.h
│ │ └── WKWebView+AFNetworking.m
├── Headers
│ ├── Private
│ │ ├── AFNetworking
│ │ │ ├── AFAutoPurgingImageCache.h
│ │ │ ├── AFCompatibilityMacros.h
│ │ │ ├── AFHTTPSessionManager.h
│ │ │ ├── AFImageDownloader.h
│ │ │ ├── AFNetworkActivityIndicatorManager.h
│ │ │ ├── AFNetworkReachabilityManager.h
│ │ │ ├── AFNetworking.h
│ │ │ ├── AFSecurityPolicy.h
│ │ │ ├── AFURLRequestSerialization.h
│ │ │ ├── AFURLResponseSerialization.h
│ │ │ ├── AFURLSessionManager.h
│ │ │ ├── UIActivityIndicatorView+AFNetworking.h
│ │ │ ├── UIButton+AFNetworking.h
│ │ │ ├── UIImageView+AFNetworking.h
│ │ │ ├── UIKit+AFNetworking.h
│ │ │ ├── UIProgressView+AFNetworking.h
│ │ │ ├── UIRefreshControl+AFNetworking.h
│ │ │ └── WKWebView+AFNetworking.h
│ │ └── SocketRocket
│ │ │ ├── SRWebSocket.h
│ │ │ └── SocketRocket.h
│ └── Public
│ │ ├── AFNetworking
│ │ ├── AFAutoPurgingImageCache.h
│ │ ├── AFCompatibilityMacros.h
│ │ ├── AFHTTPSessionManager.h
│ │ ├── AFImageDownloader.h
│ │ ├── AFNetworkActivityIndicatorManager.h
│ │ ├── AFNetworkReachabilityManager.h
│ │ ├── AFNetworking.h
│ │ ├── AFSecurityPolicy.h
│ │ ├── AFURLRequestSerialization.h
│ │ ├── AFURLResponseSerialization.h
│ │ ├── AFURLSessionManager.h
│ │ ├── UIActivityIndicatorView+AFNetworking.h
│ │ ├── UIButton+AFNetworking.h
│ │ ├── UIImageView+AFNetworking.h
│ │ ├── UIKit+AFNetworking.h
│ │ ├── UIProgressView+AFNetworking.h
│ │ ├── UIRefreshControl+AFNetworking.h
│ │ └── WKWebView+AFNetworking.h
│ │ └── SocketRocket
│ │ ├── SRWebSocket.h
│ │ └── SocketRocket.h
├── Manifest.lock
├── Pods.xcodeproj
│ └── project.pbxproj
├── SocketRocket
│ ├── LICENSE
│ ├── README.rst
│ └── SocketRocket
│ │ ├── SRWebSocket.h
│ │ ├── SRWebSocket.m
│ │ └── SocketRocket.h
└── Target Support Files
│ ├── AFNetworking
│ ├── AFNetworking-dummy.m
│ ├── AFNetworking-prefix.pch
│ ├── AFNetworking.debug.xcconfig
│ └── AFNetworking.release.xcconfig
│ ├── Pods-MKWebSocket
│ ├── Pods-MKWebSocket-acknowledgements.markdown
│ ├── Pods-MKWebSocket-acknowledgements.plist
│ ├── Pods-MKWebSocket-dummy.m
│ ├── Pods-MKWebSocket.debug.xcconfig
│ └── Pods-MKWebSocket.release.xcconfig
│ └── SocketRocket
│ ├── SocketRocket-dummy.m
│ ├── SocketRocket-prefix.pch
│ ├── SocketRocket.debug.xcconfig
│ └── SocketRocket.release.xcconfig
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## User settings
6 | xcuserdata/
7 |
8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9 | *.xcscmblueprint
10 | *.xccheckout
11 |
12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13 | build/
14 | DerivedData/
15 | *.moved-aside
16 | *.pbxuser
17 | !default.pbxuser
18 | *.mode1v3
19 | !default.mode1v3
20 | *.mode2v3
21 | !default.mode2v3
22 | *.perspectivev3
23 | !default.perspectivev3
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 |
28 | ## App packaging
29 | *.ipa
30 | *.dSYM.zip
31 | *.dSYM
32 |
33 | # CocoaPods
34 | #
35 | # We recommend against adding the Pods directory to your .gitignore. However
36 | # you should judge for yourself, the pros and cons are mentioned at:
37 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
38 | #
39 | # Pods/
40 | #
41 | # Add this line if you want to avoid checking in source code from the Xcode workspace
42 | # *.xcworkspace
43 |
44 | # Carthage
45 | #
46 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
47 | # Carthage/Checkouts
48 |
49 | Carthage/Build/
50 |
51 | # fastlane
52 | #
53 | # It is recommended to not store the screenshots in the git repo.
54 | # Instead, use fastlane to re-generate the screenshots whenever they are needed.
55 | # For more information about the recommended setup visit:
56 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
57 |
58 | fastlane/report.xml
59 | fastlane/Preview.html
60 | fastlane/screenshots/**/*.png
61 | fastlane/test_output
62 |
63 | # Code Injection
64 | #
65 | # After new code Injection tools there's a generated folder /iOSInjectionProject
66 | # https://github.com/johnno1962/injectionforxcode
67 |
68 | iOSInjectionProject/
69 |
--------------------------------------------------------------------------------
/MKWebSocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MKWebSocket.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MKWebSocket.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/MKWebSocket.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/MKWebSocket/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/5.
6 | //
7 |
8 | #import
9 |
10 | @interface AppDelegate : UIResponder
11 |
12 | @property (nonatomic, strong) UIWindow* window;
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/MKWebSocket/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/5.
6 | //
7 |
8 | #import "AppDelegate.h"
9 | #import "ViewController.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 |
21 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
22 |
23 | ViewController* rootVC = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
24 | self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootVC];
25 |
26 | [self.window makeKeyAndVisible];
27 |
28 | return YES;
29 | }
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/MKWebSocket/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/MKWebSocket/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "scale" : "1x",
46 | "size" : "20x20"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "scale" : "2x",
51 | "size" : "20x20"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "scale" : "1x",
56 | "size" : "29x29"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "scale" : "2x",
61 | "size" : "29x29"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "scale" : "1x",
66 | "size" : "40x40"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "scale" : "2x",
71 | "size" : "40x40"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "scale" : "1x",
76 | "size" : "76x76"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "scale" : "2x",
81 | "size" : "76x76"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "scale" : "2x",
86 | "size" : "83.5x83.5"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "scale" : "1x",
91 | "size" : "1024x1024"
92 | }
93 | ],
94 | "info" : {
95 | "author" : "xcode",
96 | "version" : 1
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/MKWebSocket/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/MKWebSocket/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MKWebSocket/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/MKWebSocket/Catogery/NSDate+Additions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSDate+Additions.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/8/12.
6 | //
7 |
8 | #import
9 |
10 | @interface NSDate (Additions)
11 |
12 | + (NSString *)dateToString:(NSDate *)date withDateFormat:(NSString*)dateFormat;
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/MKWebSocket/Catogery/NSDate+Additions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSDate+Additions.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/8/12.
6 | //
7 |
8 | #import "NSDate+Additions.h"
9 |
10 | @implementation NSDate (Additions)
11 |
12 | + (NSString *)dateToString:(NSDate *)date withDateFormat:(NSString*)dateFormat {
13 | static NSDateFormatter *formatter = nil;
14 | if (!formatter) {
15 | formatter = [[NSDateFormatter alloc] init];
16 | }
17 | [formatter setDateFormat:dateFormat];
18 | NSString* dateString = [formatter stringFromDate:date];
19 | return dateString;
20 | }
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/MKWebSocket/Catogery/NSObject+Additions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+Additions.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/11/16.
6 | //
7 |
8 | #import
9 |
10 | @interface NSObject (Additions)
11 |
12 | - (NSDictionary *)objectPropertyDictionary;
13 |
14 | - (NSString *)objectPropertyJSONString;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/MKWebSocket/Catogery/NSObject+Additions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSObject+Additions.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/11/16.
6 | //
7 |
8 | #import "NSObject+Additions.h"
9 | #import
10 |
11 | @interface NSArray (KeyValue)
12 |
13 | - (NSArray *)arrayRecordPropertyArray;
14 |
15 | @end
16 |
17 | @interface NSDictionary (KeyValue)
18 |
19 | - (NSDictionary *)dictionaryRecordPropertyDictionary;
20 |
21 | @end
22 |
23 | @implementation NSObject (Additions)
24 |
25 | - (NSDictionary *)objectPropertyDictionary {
26 | NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
27 |
28 | id currentClass = [self class];
29 | while (![NSStringFromClass(currentClass) isEqualToString:@"NSObject"]) {
30 | /// && ([NSBundle bundleForClass:currentClass] == [NSBundle mainBundle])
31 | unsigned int propertieCount = 0;
32 | objc_property_t* properties = class_copyPropertyList(currentClass, &propertieCount);
33 |
34 | @autoreleasepool {
35 | for (int i = 0; i < propertieCount; i++) {
36 | objc_property_t property = properties[i];
37 |
38 | const char* name = property_getName(property);
39 | NSString* propertyName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
40 |
41 | NSObject* value = [self valueForKey:propertyName];
42 | Class objectClass = object_getClass(value);
43 |
44 | if (objectClass != nil) {
45 | NSString* className = NSStringFromClass(objectClass);
46 |
47 | if ([className rangeOfString:@"NS"].length != 0) {
48 | if ([className rangeOfString:@"String"].length != 0) {
49 | parameters[propertyName] = value;
50 | } else if ([className rangeOfString:@"Number"].length != 0) {
51 | parameters[propertyName] = value;
52 | } else if ([className rangeOfString:@"Data"].length != 0) {
53 | parameters[propertyName] = value;
54 | } else if ([className rangeOfString:@"Array"].length != 0) {
55 | NSArray* arr = [(NSArray *)value arrayRecordPropertyArray];
56 | parameters[propertyName] = arr;
57 | } else if ([className rangeOfString:@"Dictionary"].length != 0) {
58 | NSDictionary* dic = [(NSDictionary *)value dictionaryRecordPropertyDictionary];
59 | parameters[propertyName] = dic;
60 | } else {
61 | continue;
62 | }
63 | } else if ([className rangeOfString:@"Block"].length != 0) {
64 | continue;
65 | } else {
66 | NSDictionary* dic = [(NSObject *)value objectPropertyDictionary];
67 | parameters[propertyName] = dic;
68 | }
69 | }
70 | }
71 | }
72 |
73 | if (properties) {
74 | free(properties);
75 | }
76 | currentClass = [currentClass superclass];
77 | }
78 | return parameters;
79 | }
80 |
81 | - (NSString *)objectPropertyJSONString {
82 | NSDictionary *objectPropertys = [self objectPropertyDictionary];
83 | NSData *JSONData = [NSJSONSerialization dataWithJSONObject:objectPropertys options:kNilOptions error:nil];
84 | NSString *JSONString = [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
85 | return JSONString;
86 | }
87 |
88 | @end
89 |
90 |
91 | @implementation NSArray (KeyValue)
92 |
93 | - (NSArray *)arrayRecordPropertyArray {
94 |
95 | NSInteger count = self.count;
96 |
97 | NSMutableArray* parameters = [NSMutableArray arrayWithCapacity:count];
98 | for (int i = 0; i < count; i++) {
99 |
100 | NSObject* value = self[i];
101 |
102 | Class objectClass = object_getClass(value);
103 |
104 | if (objectClass != nil) {
105 | NSString* className = NSStringFromClass(objectClass);
106 |
107 | if ([className rangeOfString:@"NS"].length != 0) {
108 | if ([className rangeOfString:@"String"].length != 0) {
109 | [parameters addObject:value];
110 | }
111 | else if ([className rangeOfString:@"Number"].length != 0) {
112 | [parameters addObject:value];
113 | }
114 | else if ([className rangeOfString:@"Data"].length != 0) {
115 | [parameters addObject:value];
116 | }
117 | else if ([className rangeOfString:@"Array"].length != 0) {
118 | NSArray* arr = [(NSArray *)value arrayRecordPropertyArray];
119 | [parameters addObject: arr];
120 | }
121 | else if ([className rangeOfString:@"Dictionary"].length != 0) {
122 | NSDictionary* dic = [(NSDictionary *)value dictionaryRecordPropertyDictionary];
123 | [parameters addObject: dic];
124 | }
125 | else {
126 | continue;
127 | }
128 | }
129 | else if ([className rangeOfString:@"Block"].length != 0) {
130 | continue;
131 | }
132 | else {
133 | NSDictionary* dic = [(NSObject *)value objectPropertyDictionary];
134 | [parameters addObject: dic];
135 | }
136 | }
137 | }
138 | return parameters;
139 | }
140 |
141 | @end
142 |
143 |
144 | @implementation NSDictionary (KeyValue)
145 |
146 | - (NSDictionary *)dictionaryRecordPropertyDictionary {
147 | NSInteger count = self.allKeys.count;
148 |
149 | NSMutableDictionary* parameters = [NSMutableDictionary dictionaryWithCapacity:count];
150 |
151 | for (int i = 0; i < count; i++) {
152 |
153 | NSString* key = self.allKeys[i];
154 | NSObject* value = self[key];
155 |
156 | Class objectClass = object_getClass(value);
157 |
158 | if (objectClass != nil) {
159 | NSString* className = NSStringFromClass(objectClass);
160 |
161 | if ([className rangeOfString:@"NS"].length != 0) {
162 | if ([className rangeOfString:@"String"].length != 0) {
163 | [parameters setObject:value forKey:key];
164 | }
165 | else if ([className rangeOfString:@"Number"].length != 0) {
166 | [parameters setObject:value forKey:key];
167 | }
168 | else if ([className rangeOfString:@"Data"].length != 0) {
169 | [parameters setObject:value forKey:key];
170 | }
171 | else if ([className rangeOfString:@"Array"].length != 0) {
172 | NSArray* arr = [(NSArray *)value arrayRecordPropertyArray];
173 | [parameters setObject:arr forKey:key];
174 | }
175 | else if ([className rangeOfString:@"Dictionary"].length != 0) {
176 | NSDictionary* dic = [(NSDictionary *)value dictionaryRecordPropertyDictionary];
177 | [parameters setObject:dic forKey:key];
178 | }
179 | else {
180 | continue;
181 | }
182 | }
183 | else if ([className rangeOfString:@"Block"].length != 0) {
184 | continue;
185 | }
186 | else {
187 | NSDictionary* dic = [(NSObject *)value objectPropertyDictionary];
188 | [parameters setObject:dic forKey:key];
189 | }
190 | }
191 | }
192 | return parameters;
193 | }
194 |
195 | @end
196 |
--------------------------------------------------------------------------------
/MKWebSocket/GCDObjc/GCDConstant.h:
--------------------------------------------------------------------------------
1 | //
2 | // GCDConstant.h
3 | // Basic
4 | //
5 | // Created by zhengmiaokai on 2018/8/18.
6 | // Copyright © 2018年 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #ifndef GCDConstant_h
10 | #define GCDConstant_h
11 |
12 | #import "GCDSource.h"
13 | #import "GCDSemaphore.h"
14 |
15 | #endif /* GCDConstant_h */
16 |
--------------------------------------------------------------------------------
/MKWebSocket/GCDObjc/GCDSemaphore.h:
--------------------------------------------------------------------------------
1 | //
2 | // GCDSemaphore.h
3 | // Basic
4 | //
5 | // Created by zhengmiaokai on 2018/8/13.
6 | // Copyright © 2018年 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | /**
12 | ** 信号量为:0; wait-signal:把异步操作转为同步操作
13 | ** 信号量为:1、2...设置线程最多的执行数量
14 | **/
15 |
16 | @interface GCDSemaphore : NSObject
17 |
18 | + (instancetype)semaphoreWithValue:(long)value;
19 |
20 | + (instancetype)semaphore;
21 |
22 | - (void)wait;
23 |
24 | - (void)signal;
25 |
26 | @end
27 |
28 | /* 示例
29 | --------------------------------------------------------------
30 | GCDSemaphore *semaphore = [GCDSemaphore semaphoreWithValue:0];
31 | [GCDQueue asyncGlobal:^{
32 | // do something
33 | [semaphore signal];
34 | }];
35 | [semaphore wait];
36 | // continue after signal
37 | --------------------------------------------------------------
38 | */
39 |
--------------------------------------------------------------------------------
/MKWebSocket/GCDObjc/GCDSemaphore.m:
--------------------------------------------------------------------------------
1 | //
2 | // GCDSemaphore.m
3 | // Basic
4 | //
5 | // Created by zhengmiaokai on 2018/8/13.
6 | // Copyright © 2018年 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import "GCDSemaphore.h"
10 |
11 | @interface GCDSemaphore ()
12 |
13 | @property (nonatomic) dispatch_semaphore_t semaphore;
14 |
15 | @end
16 |
17 | @implementation GCDSemaphore
18 |
19 | + (instancetype)semaphoreWithValue:(long)value {
20 | GCDSemaphore* instance = [[GCDSemaphore alloc] init];
21 | instance.semaphore = dispatch_semaphore_create(value);
22 | return instance;
23 | }
24 |
25 | + (instancetype)semaphore {
26 | GCDSemaphore* semaphore = [GCDSemaphore semaphoreWithValue:1];
27 | return semaphore;
28 | }
29 |
30 | - (void)wait {
31 | dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
32 | }
33 |
34 | - (void)signal {
35 | dispatch_semaphore_signal(_semaphore);
36 | }
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/MKWebSocket/GCDObjc/GCDSource.h:
--------------------------------------------------------------------------------
1 | //
2 | // GCDSource.h
3 | // Basic
4 | //
5 | // Created by zhengmiaokai on 2019/7/19.
6 | // Copyright © 2019 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface GCDSource : NSObject
12 |
13 | /* 方法参数说明
14 | * timeInterval: 定时间隔
15 | * repeats:是否重复
16 | * timeBlock:定时回调
17 | * immediately:是否马上启动(默认为NO)
18 | */
19 | - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats timerBlock:(void(^)(void))timerBlock;
20 | - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats timerBlock:(void(^)(void))timerBlock immediately:(BOOL)immediately;
21 |
22 | /* 方法参数说明
23 | * timeInterval: 定时间隔
24 | * repeats:是否重复
25 | * timeBlock:定时回调
26 | * timerQueue:执行定时的队列
27 | * blockQueue:执行回调的队列
28 | * immediately:是否马上启动(默认为NO)
29 | */
30 | - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats timerBlock:(void(^)(void))timerBlock timerQueue:(dispatch_queue_t)timerQueue blockQueue:(dispatch_queue_t)blockQueue immediately:(BOOL)immediately;
31 |
32 | - (instancetype)init UNAVAILABLE_ATTRIBUTE;
33 |
34 | - (void)pauseTimer; // 挂起与恢复必须平衡,不然会crash
35 |
36 | - (void)resumeTimer;
37 |
38 | - (void)stopTimer; // 不能在挂起的状态cancel,需要恢复定时器再cancel
39 |
40 | @end
41 |
42 | /* 示例
43 | ----------------------------------------------------------------------------
44 | _timer = [[GCDSource alloc] initWithTimeInterval:3 repeats:YES timerBlock:^{
45 | // do something
46 | }];
47 |
48 | [_timer pauseTimer];
49 | [_timer resumeTimer];
50 | [_timer stopTimer];
51 | ----------------------------------------------------------------------------
52 | */
53 |
--------------------------------------------------------------------------------
/MKWebSocket/GCDObjc/GCDSource.m:
--------------------------------------------------------------------------------
1 | //
2 | // GCDSource.m
3 | // Basic
4 | //
5 | // Created by zhengmiaokai on 2019/7/19.
6 | // Copyright © 2019 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import "GCDSource.h"
10 |
11 | @interface GCDSource () {
12 | NSTimeInterval _timeInterval;
13 | BOOL _immediately; // 是否马上开始
14 | BOOL _isSuspend; // 是否挂起
15 | NSRecursiveLock* _lock;
16 | }
17 | @property (nonatomic, assign) BOOL repeats;
18 | @property (nonatomic, strong) dispatch_source_t timer;
19 |
20 | @property (nonatomic, strong) dispatch_queue_t timerQueue;
21 | @property (nonatomic, strong) dispatch_queue_t blockQueue;
22 |
23 | @property (nonatomic, copy) void(^timerBlock)(void);
24 |
25 | @end
26 |
27 | @implementation GCDSource
28 |
29 | - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats timerBlock:(void(^)(void))timerBlock timerQueue:(dispatch_queue_t)timerQueue blockQueue:(dispatch_queue_t)blockQueue immediately:(BOOL)immediately {
30 | self = [super init];
31 | if (self) {
32 | _timeInterval = timeInterval;
33 | _immediately = immediately;
34 | self.repeats = repeats;
35 | self.timerBlock = timerBlock;
36 | self.timerQueue = timerQueue;
37 | self.blockQueue = blockQueue;
38 |
39 | [self initTimer];
40 | }
41 | return self;
42 | }
43 |
44 | - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats timerBlock:(void(^)(void))timerBlock {
45 | return [self initWithTimeInterval:timeInterval repeats:repeats timerBlock:timerBlock immediately:NO];
46 | }
47 |
48 | - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval repeats:(BOOL)repeats timerBlock:(void(^)(void))timerBlock immediately:(BOOL)immediately {
49 | self = [super init];
50 | if (self) {
51 | _timeInterval = timeInterval;
52 | _immediately = immediately;
53 | _repeats = repeats;
54 | self.timerBlock = timerBlock;
55 |
56 | [self initTimer];
57 | }
58 | return self;
59 | }
60 |
61 | - (void)initTimer {
62 | dispatch_queue_t timerQueue = self.timerQueue ? self.timerQueue : dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
63 | dispatch_queue_t blockQueue = self.blockQueue ? self.blockQueue : dispatch_get_main_queue();
64 |
65 | self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, timerQueue);
66 | _lock = [[NSRecursiveLock alloc] init];
67 |
68 | /*
69 | 参数二:定时器开始时间,设置为“_timeInterval * NSEC_PER_SEC”,”当前时间 + _timeInterval“ 开始
70 | 参数三:定时器间隔时长
71 | */
72 | NSTimeInterval walltime = (_immediately == YES ? 0 : _timeInterval);
73 | dispatch_source_set_timer(_timer, dispatch_walltime(NULL, walltime * NSEC_PER_SEC), _timeInterval * NSEC_PER_SEC, 0);
74 | dispatch_source_set_event_handler(_timer, ^{
75 | dispatch_async(blockQueue, ^{
76 | self.timerBlock();
77 | });
78 | if (self.repeats == NO) {
79 | [self stopTimer];
80 | }
81 | });
82 | dispatch_resume(_timer);
83 | _isSuspend = NO;
84 | }
85 |
86 | - (void)pauseTimer {
87 | [_lock lock];
88 | if(self.timer && _isSuspend == NO){
89 | dispatch_suspend(_timer);
90 | _isSuspend = YES;
91 | }
92 | [_lock unlock];
93 | }
94 |
95 | - (void)resumeTimer {
96 | [_lock lock];
97 | if(self.timer && _isSuspend == YES){
98 | dispatch_resume(_timer);
99 | _isSuspend = NO;
100 | }
101 | [_lock unlock];
102 | }
103 |
104 | - (void)stopTimer {
105 | [_lock lock];
106 | if(self.timer){
107 | if (_isSuspend == YES) {
108 | [self resumeTimer];
109 | }
110 | dispatch_source_cancel(_timer);
111 | _timer = nil;
112 | }
113 | [_lock unlock];
114 | }
115 |
116 | - (void)dealloc {
117 | [self stopTimer];
118 | }
119 |
120 | @end
121 |
--------------------------------------------------------------------------------
/MKWebSocket/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UIApplicationSupportsIndirectInputEvents
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/MKWebSocket/MKTestModule.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKTestModule.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/12.
6 | //
7 |
8 | #import "MKWebSocketBaseModule.h"
9 |
10 | @protocol MKTestModuleProtocol
11 |
12 | - (void)refreshOrder:(id)data;
13 |
14 | @end
15 |
16 |
17 | @interface MKTestModule : MKWebSocketBaseModule
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/MKWebSocket/MKTestModule.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKTestModule.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/12.
6 | //
7 |
8 | #import "MKTestModule.h"
9 | #import "MKWebSocketMessage.h"
10 |
11 | @implementation MKTestModule
12 |
13 | - (void)webSocketClient:(id)webSocketClient didReceiveMessage:(MKWebSocketMessage *)message {
14 | NSDictionary* data = @{@"type": @"5"};
15 | NSString* type = [data objectForKey:@"type"];
16 | if (type.intValue == 7) {
17 | [self enumerateDelegate:^(id delegate) {
18 | if ([delegate respondsToSelector:@selector(refreshOrder:)]) {
19 | [(id )delegate refreshOrder:message];
20 | }
21 | }];
22 |
23 | } else {
24 | [super webSocketClient:webSocketClient didReceiveMessage:message];
25 | }
26 | }
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/MKWebSocket/MKWSPingVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKWSPingVC.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/8/11.
6 | //
7 |
8 | #import
9 |
10 | @interface MKWSPingVC : UIViewController
11 |
12 | @end
13 |
14 |
--------------------------------------------------------------------------------
/MKWebSocket/MKWSPingVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKWSPingVC.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/8/11.
6 | //
7 |
8 | #import "MKWSPingVC.h"
9 | #import "MKWebSocketClient.h"
10 |
11 | @interface MKWSPingVC ()
12 |
13 | @property (nonatomic, strong) UITableView* tableView;
14 |
15 | @end
16 |
17 | @implementation MKWSPingVC
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view.
22 |
23 | [self.view addSubview:self.tableView];
24 |
25 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData:) name:MKWebSocketPingNotification object:nil];
26 | }
27 |
28 | - (void)refreshData:(NSNotification *)notification {
29 | dispatch_async(dispatch_get_main_queue(), ^{
30 | [self.tableView reloadData];
31 | });
32 | }
33 |
34 | - (void)dealloc {
35 | [[NSNotificationCenter defaultCenter] removeObserver:self];
36 | }
37 |
38 | - (UITableView *)tableView {
39 | if (_tableView == nil) {
40 | _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 88, self.view.frame.size.width, self.view.frame.size.height - 88) style:UITableViewStylePlain];
41 | _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
42 | _tableView.delegate = self;
43 | _tableView.dataSource = self;
44 | [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MKWSPingCellID"];
45 | }
46 | return _tableView;
47 | }
48 |
49 | #pragma mark - UITableViewDataSource -
50 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
51 | return 1;
52 | }
53 |
54 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
55 | return [MKWebSocketClient sharedInstance].pingDatas.count;
56 | }
57 |
58 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
59 | return 56;
60 | }
61 |
62 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
63 | UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"MKWSPingCellID"];
64 | cell.textLabel.text = [[MKWebSocketClient sharedInstance].pingDatas objectAtIndex:indexPath.row];
65 | return cell;
66 | }
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/MKWebSocket/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/5.
6 | //
7 |
8 | #import
9 |
10 | @interface ViewController : UIViewController
11 |
12 | @property (weak, nonatomic) IBOutlet UITextField* adressTF;
13 | @property (weak, nonatomic) IBOutlet UIButton* connectBtn;
14 | @property (weak, nonatomic) IBOutlet UIButton* pingBtn;
15 | @property (weak, nonatomic) IBOutlet UIButton* closeBtn;
16 |
17 | @property (weak, nonatomic) IBOutlet UITextField* contentTF;
18 | @property (weak, nonatomic) IBOutlet UIButton* sendBtn;
19 | @property (weak, nonatomic) IBOutlet UIButton* cleanBtn;
20 |
21 | @property (weak, nonatomic) IBOutlet UITextView* contentTV;
22 |
23 | - (IBAction)connect:(UIButton *)sender;
24 | - (IBAction)close:(UIButton *)sender;
25 | - (IBAction)send:(UIButton *)sender;
26 | - (IBAction)clean:(UIButton *)sender;
27 | - (IBAction)jumpPingVC:(UIButton *)sender;
28 |
29 | @end
30 |
--------------------------------------------------------------------------------
/MKWebSocket/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/5.
6 | //
7 |
8 | #import "ViewController.h"
9 | #import "MKWebSocketClient.h"
10 | #import "MKWebSocketMessage.h"
11 | #import "MKWMesssagePackage.h"
12 | #import "MKTestModule.h"
13 | #import "MKWSPingVC.h"
14 |
15 | @interface ViewController ()
16 |
17 | @end
18 |
19 | @implementation ViewController
20 |
21 | - (void)viewDidLoad {
22 | [super viewDidLoad];
23 | self.view.backgroundColor = [UIColor whiteColor];
24 | // Do any additional setup after loading the view.
25 |
26 | /* 添加子模块代理 */
27 | [SOCKET_MODULE(MKTestModule) addDelegate:self];
28 |
29 | /* 添加主模块代理
30 | [[MKWebSocketClient sharedInstance] addDelegate:self];
31 | */
32 |
33 | _connectBtn.enabled = YES;
34 | _pingBtn.enabled = NO;
35 | _sendBtn.enabled = NO;
36 | _closeBtn.enabled = NO;
37 |
38 | // 模拟回包数据
39 | NSString *ackPackage = [MKWSendPackage ackWithPayload:@{@"msgId": @"8569745369215698"}];
40 | NSLog(@"ack_package: %@", ackPackage);
41 | }
42 |
43 | - (void)dealloc {
44 | /* 移除子模块代理 */
45 | [SOCKET_MODULE(MKTestModule) removeDelegate:self];
46 |
47 | /* 移除主模块代理
48 | [[MKWebSocketClient sharedInstance] removeDelegate:self];
49 | */
50 | }
51 |
52 | - (IBAction)connect:(UIButton *)sender {
53 | if (_adressTF.text.length) {
54 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_adressTF.text]];
55 | request.timeoutInterval = 25;
56 | [request setValue:@"" forHTTPHeaderField:@"Cookie"];
57 |
58 | [MKWebSocketClient sharedInstance].serverRequest = request;
59 | [[MKWebSocketClient sharedInstance] connect];
60 | }
61 | }
62 |
63 | - (IBAction)close:(UIButton *)sender {
64 | [[MKWebSocketClient sharedInstance] disconnect];
65 | }
66 |
67 | - (IBAction)send:(UIButton *)sender {
68 | if (_contentTF.text.length) {
69 | [[MKWebSocketClient sharedInstance] sendMessage:_contentTF.text];
70 | }
71 | }
72 |
73 | - (IBAction)clean:(UIButton *)sender {
74 | _contentTV.text = nil;
75 | [self.contentTV setContentOffset:CGPointZero];
76 | }
77 |
78 | - (IBAction)jumpPingVC:(UIButton *)sender {
79 | MKWSPingVC* pingVC = [[MKWSPingVC alloc] init];
80 | [self.navigationController pushViewController:pingVC animated:YES];
81 | }
82 |
83 | - (void)scollToBottom {
84 | if (self.contentTV.contentSize.height > self.contentTV.frame.size.height) {
85 | [self.contentTV setContentOffset:CGPointMake(0, self.contentTV.contentSize.height - self.contentTV.frame.size.height) animated:YES];
86 | }
87 | }
88 |
89 | #pragma mark - MKWebSocketClientDelegate -
90 | - (void)webSocketClient:(id)webSocketClient didReceiveMessage:(MKWebSocketMessage *)message {
91 | self.contentTV.text = [NSString stringWithFormat:@"%@\n\n服务端:%@", self.contentTV.text, message.message];
92 | [self scollToBottom];
93 | }
94 |
95 | - (void)webSocketClient:(id)webSocketClient didReciveStatusChanged:(MKWebSocketStatus)status {
96 | if (status == MKWebSocketStatusOpen) {
97 | self.contentTV.text = [NSString stringWithFormat:@"%@\n\n%@", self.contentTV.text, @"已连接对应的服务。。。"];
98 | [self scollToBottom];
99 |
100 | self.pingBtn.enabled = YES;
101 | self.sendBtn.enabled = YES;
102 | self.closeBtn.enabled = YES;
103 | self.connectBtn.enabled = NO;
104 | } else {
105 | self.pingBtn.enabled = NO;
106 | self.sendBtn.enabled = NO;
107 | self.closeBtn.enabled = NO;
108 | self.connectBtn.enabled = YES;
109 |
110 | if (status == MKWebSocketStatusClose) {
111 | self.contentTV.text = [NSString stringWithFormat:@"%@\n\n%@", self.contentTV.text, @"服务已断开。。。"];
112 | [self scollToBottom];
113 | } else if (status == MKWebSocketStatusConnecting) {
114 | self.contentTV.text = [NSString stringWithFormat:@"%@\n\n%@", self.contentTV.text, @"正在连接中。。。"];
115 | [self scollToBottom];
116 | }
117 | }
118 | }
119 |
120 | - (void)webSocketClient:(id)webSocketClient didSendMessage:(MKWebSocketMessage *)message {
121 | self.contentTV.text = [NSString stringWithFormat:@"%@\n\n客户端:%@", self.contentTV.text, message.message];
122 | [self scollToBottom];
123 | }
124 |
125 | - (void)refreshOrder:(id)data {
126 |
127 | }
128 |
129 | @end
130 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWMesssagePackage.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKWMesssagePackage.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/11/15.
6 | //
7 |
8 | #import
9 |
10 | @interface MKWSendPackage : NSObject
11 |
12 | @property (nonatomic, copy) NSString *msgType; // 消息类型,'ACK' 消息回包、'ASK' 数据请求、可扩展...
13 | @property (nonatomic, copy) NSString *source; // 消息来源,'CLIENT' 客户端
14 | @property (nonatomic, copy) NSDictionary *payload; // 消息负载
15 | @property (nonatomic, assign) NSTimeInterval timeInterval; // 时间戳(毫秒)
16 |
17 | /// ACK消息体
18 | + (NSString *)ackWithPayload:(NSDictionary *)payload;
19 |
20 | /// ASK消息体
21 | + (NSString *)askWithPayload:(NSDictionary *)payload;
22 |
23 | @end
24 |
25 | @interface MKWReceivePackage : NSObject
26 |
27 | @property (nonatomic, copy) NSString *msgId; // 消息id
28 | @property (nonatomic, copy) NSString *msgType; // 消息类型,'ANSWER' 数据响应、'PUSH' 信息推送、可扩展...
29 | @property (nonatomic, copy) NSString *source; // 消息来源,'SERVER' 服务端
30 | @property (nonatomic, copy) NSDictionary *payload; // 消息负载
31 | @property (nonatomic, assign) NSTimeInterval timeInterval; // 时间戳(毫秒)
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWMesssagePackage.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKWMesssagePackage.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/11/15.
6 | //
7 |
8 | #import "MKWMesssagePackage.h"
9 | #import "NSObject+Additions.h"
10 |
11 | @implementation MKWSendPackage
12 |
13 | + (NSString *)ackWithPayload:(NSDictionary *)payload {
14 | MKWSendPackage* item = [[MKWSendPackage alloc] init];
15 | item.msgType = @"ACK";
16 | item.source = @"CLIENT";
17 | item.payload = payload; // keys: msgId
18 | item.timeInterval = (NSInteger)([[NSDate date] timeIntervalSince1970] * 1000);
19 | return [item objectPropertyJSONString];
20 | }
21 |
22 | + (NSString *)askWithPayload:(NSDictionary *)payload {
23 | MKWSendPackage* item = [[MKWSendPackage alloc] init];
24 | item.msgType = @"ASK";
25 | item.source = @"CLIENT";
26 | item.payload = payload; // keys: action、parameter、askId
27 | item.timeInterval = (NSInteger)([[NSDate date] timeIntervalSince1970] * 1000);
28 | return [item objectPropertyJSONString];
29 | }
30 |
31 | @end
32 |
33 | @implementation MKWReceivePackage
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocketBaseModule.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKWSBaseModule.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/23.
6 | // Copyright © 2021 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MKWebSocktDelegate.h"
11 |
12 | /* 添加对应的业务处理 */
13 |
14 | @interface MKWebSocketBaseModule : NSObject
15 |
16 | /// 是否在主线程回调(default:YES)
17 | @property (nonatomic, assign) BOOL delegateOnMainQueue;
18 |
19 | /// 遍历获取delegate
20 | - (void)enumerateDelegate:(void(^)(id delegate))enumerateHandler;
21 |
22 | - (void)addDelegate:(id )delegate;
23 | - (void)removeDelegate:(id )delegate;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocketBaseModule.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKWSBaseModule.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/23.
6 | // Copyright © 2021 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import "MKWebSocketBaseModule.h"
10 |
11 | @interface MKWebSocketBaseModule ()
12 |
13 | @property (nonatomic, strong) NSMutableDictionary* delegateItems;
14 | @property (nonatomic, strong) NSRecursiveLock* lock;
15 |
16 | @end
17 |
18 | @implementation MKWebSocketBaseModule
19 |
20 | - (instancetype)init {
21 | self = [super init];
22 | if (self) {
23 | self.delegateItems = [[NSMutableDictionary alloc] init];
24 | self.delegateOnMainQueue = YES;
25 | }
26 | return self;
27 | }
28 |
29 | - (NSDictionary *)getDelegateItems {
30 | NSDictionary* delegateItems = nil;
31 | @synchronized (self) {
32 | delegateItems = [_delegateItems copy];
33 | }
34 | return delegateItems;
35 | }
36 |
37 | - (void)enumerateDelegate:(void(^)(id delegate))enumerateHandler {
38 | [MKWebSocketUitls performOnMainThread:^{
39 | NSDictionary* delegateItems = [self getDelegateItems];
40 | [delegateItems enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, MKDelegateItem *delegateItem, BOOL * _Nonnull stop) {
41 | if (enumerateHandler) {
42 | enumerateHandler(delegateItem.delegate);
43 | }
44 | }];
45 | } available:_delegateOnMainQueue];
46 | }
47 |
48 | - (void)addDelegate:(id)delegate {
49 | @synchronized (self) {
50 | MKDelegateItem* delegateItem = [[MKDelegateItem alloc] initWithDelegate:delegate];
51 | [self.delegateItems setValue:delegateItem forKey:delegateItem.delegateTag];
52 | }
53 | }
54 |
55 | - (void)removeDelegate:(id )delegate {
56 | @synchronized (self) {
57 | [_delegateItems removeObjectForKey:[MKWebSocketUitls generateTag:delegate]];
58 | }
59 | }
60 |
61 | #pragma mark -- MKWebSocketClientDelegate --
62 | - (void)webSocketClient:(id)webSocketClient didReceiveMessage:(id)message {
63 | [MKWebSocketUitls performOnMainThread:^{
64 | NSDictionary* delegateItems = [self getDelegateItems];
65 | for (NSString* key in delegateItems) {
66 | MKDelegateItem* obj = [delegateItems objectForKey:key];
67 | if ([obj.delegate respondsToSelector:@selector(webSocketClient:didReceiveMessage:)]) {
68 | [obj.delegate webSocketClient:self didReceiveMessage:message];
69 | }
70 | }
71 | } available:_delegateOnMainQueue];
72 | }
73 |
74 | - (void)webSocketClient:(id)webSocketClient didSendMessage:(id)message {
75 | [MKWebSocketUitls performOnMainThread:^{
76 | NSDictionary* delegateItems = [self getDelegateItems];
77 | for (NSString* key in delegateItems) {
78 | MKDelegateItem* obj = [delegateItems objectForKey:key];
79 | if ([obj.delegate respondsToSelector:@selector(webSocketClient:didReceiveMessage:)]) {
80 | [obj.delegate webSocketClient:self didSendMessage:message];
81 | }
82 | }
83 | } available:_delegateOnMainQueue];
84 | }
85 |
86 | - (void)webSocketClient:(id)webSocketClient didReciveStatusChanged:(MKWebSocketStatus)status {
87 | [MKWebSocketUitls performOnMainThread:^{
88 | NSDictionary* delegateItems = [self getDelegateItems];
89 | for (NSString* key in delegateItems) {
90 | MKDelegateItem* obj = [delegateItems objectForKey:key];
91 | if ([obj.delegate respondsToSelector:@selector(webSocketClient:didReciveStatusChanged:)]) {
92 | [obj.delegate webSocketClient:self didReciveStatusChanged:status];
93 | }
94 | }
95 | } available:_delegateOnMainQueue];
96 | }
97 |
98 | @end
99 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocketClient.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKWebSocketClient.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/21.
6 | // Copyright © 2021年 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MKWebSocktDelegate.h"
12 |
13 | @interface MKWebSocketClient : NSObject
14 |
15 | // 用于确认ping-pong是否正常,属于测试数据
16 | @property (nonatomic, strong, readonly) NSMutableArray* pingDatas;
17 |
18 | @property (nonatomic, copy) NSString* serverLink;
19 | @property (nonatomic, strong) NSURLRequest* serverRequest;
20 |
21 | + (instancetype)sharedInstance;
22 |
23 | - (void)connect;
24 | - (void)reConnect;
25 | - (void)disconnect;
26 |
27 | - (void)sendData:(NSString *)data;
28 | - (void)sendMessage:(NSString *)data;
29 |
30 | - (void)addDelegate:(id )delegate;
31 | - (void)removeDelegate:(id )delegate;
32 |
33 | #pragma mark - 模块化扩展(聊天、系统消息等) -
34 | - (id)socketModule:(NSString *)cls;
35 | - (void)removeSocketModule:(NSString*)cls;
36 |
37 | @end
38 |
39 | #define SOCKET_MODULE(cls) ((cls*)[[MKWebSocketClient sharedInstance] socketModule:@#cls])
40 | #define REMOVE_SOCKET_MODULE(cls) [[MKWebSocketClient sharedInstance] removeSocketModule:@#cls]
41 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocketMessage.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKWebSocketMessage.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/22.
6 | // Copyright © 2021年 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MKWMesssagePackage.h"
11 |
12 | @interface MKWebSocketMessage : NSObject
13 |
14 | /// 原始数据
15 | @property (nonatomic, strong) id message;
16 |
17 | /// 消息模型
18 | @property (nonatomic, strong) MKWReceivePackage *model;
19 |
20 | + (instancetype)modelWithMessage:(id)message;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocketMessage.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKWebSocketMessage.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/22.
6 | // Copyright © 2021年 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import "MKWebSocketMessage.h"
10 |
11 | @implementation MKWebSocketMessage
12 |
13 | + (instancetype)modelWithMessage:(id)message {
14 | MKWebSocketMessage* item = [[MKWebSocketMessage alloc] init];
15 | item.message = message;
16 | return item;
17 | }
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocktDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKDelegateItem.h
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/21.
6 | // Copyright © 2021 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import "SocketRocket.h"
10 |
11 | extern NSString * const MKWebSocketDidOpenNotification;
12 | extern NSString * const MKWebSocketDidCloseNotification;
13 | extern NSString * const MKWebSocketDidFailNotification;
14 | extern NSString * const MKWebSocketDidReciveNotification;
15 |
16 | extern NSString * const MKWebSocketPingNotification;
17 |
18 | typedef NS_ENUM(NSInteger, MKWebSocketStatus) {
19 | MKWebSocketStatusOpen = 1, /// 连接成功
20 | MKWebSocketStatusClose = 2, /// 断开连接
21 | MKWebSocketStatusConnecting = 3, /// 连接中
22 | };
23 |
24 | @protocol MKWebSocketClientDelegate
25 |
26 | @required
27 | - (void)webSocketClient:(id)webSocketClient didReceiveMessage:(id)message;
28 |
29 | @optional
30 | - (void)webSocketClient:(id)webSocketClient didSendMessage:(id)message;
31 | - (void)webSocketClient:(id)webSocketClient didReciveStatusChanged:(MKWebSocketStatus)status;
32 |
33 | @end
34 |
35 |
36 | @interface MKDelegateItem : NSObject
37 |
38 | @property (nonatomic, weak) id delegate;
39 | @property (nonatomic, copy, readonly) NSString* delegateTag;
40 |
41 | - (instancetype)initWithDelegate:(id)delegate;
42 |
43 | @end
44 |
45 |
46 | @interface MKWebSocketUitls: NSObject
47 |
48 | + (NSString *)generateTag:(id )delegate;
49 |
50 | + (void)performOnMainThread:(void(^)(void))block available:(BOOL)available;
51 |
52 | @end
53 |
--------------------------------------------------------------------------------
/MKWebSocket/WebSocket/MKWebSocktDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKDelegateItem.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/6/21.
6 | // Copyright © 2021 zhengmiaokai. All rights reserved.
7 | //
8 |
9 | #import "MKWebSocktDelegate.h"
10 |
11 | NSString * const MKWebSocketDidOpenNotification = @"webSocketDidOpenNotification";
12 | NSString * const MKWebSocketDidCloseNotification = @"webSocketDidCloseNotification";
13 | NSString * const MKWebSocketDidFailNotification = @"webSocketDidFailNotification";
14 | NSString * const MKWebSocketDidReciveNotification = @"webSocketDidReciveNotification";
15 |
16 | NSString * const MKWebSocketPingNotification = @"webSocketPingNotification";
17 |
18 | @implementation MKDelegateItem
19 |
20 | - (instancetype)initWithDelegate:(id )delegate {
21 | self = [super init];
22 | if (self) {
23 | self.delegate = delegate;
24 | _delegateTag = [MKWebSocketUitls generateTag:delegate];
25 | }
26 | return self;
27 | }
28 |
29 | @end
30 |
31 |
32 | @implementation MKWebSocketUitls
33 |
34 | + (NSString *)generateTag:(id )delegate {
35 | return [NSString stringWithFormat:@"MKWebSockt-%p", delegate];
36 | }
37 |
38 | + (void)performOnMainThread:(void(^)(void))block available:(BOOL)available {
39 | if (!block) return;
40 |
41 | if (!available) {
42 | block();
43 | } else {
44 | if ([NSThread isMainThread]) {
45 | block();
46 | } else {
47 | dispatch_async(dispatch_get_main_queue(), ^{
48 | block();
49 | });
50 | }
51 | }
52 | }
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/MKWebSocket/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // MKWebSocket
4 | //
5 | // Created by zhengmiaokai on 2021/7/5.
6 | //
7 |
8 | #import
9 | #import "AppDelegate.h"
10 |
11 | int main(int argc, char * argv[]) {
12 | NSString * appDelegateClassName;
13 | @autoreleasepool {
14 | // Setup code that might create autoreleased objects goes here.
15 | appDelegateClassName = NSStringFromClass([AppDelegate class]);
16 | }
17 | return UIApplicationMain(argc, argv, nil, appDelegateClassName);
18 | }
19 |
--------------------------------------------------------------------------------
/Podfile:
--------------------------------------------------------------------------------
1 | source 'https://github.com/CocoaPods/Specs.git'
2 | platform:ios,'10.0'
3 |
4 | target "MKWebSocket" do
5 |
6 | pod 'SocketRocket'
7 | pod 'AFNetworking', '~> 4.0.1'
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - AFNetworking (4.0.1):
3 | - AFNetworking/NSURLSession (= 4.0.1)
4 | - AFNetworking/Reachability (= 4.0.1)
5 | - AFNetworking/Security (= 4.0.1)
6 | - AFNetworking/Serialization (= 4.0.1)
7 | - AFNetworking/UIKit (= 4.0.1)
8 | - AFNetworking/NSURLSession (4.0.1):
9 | - AFNetworking/Reachability
10 | - AFNetworking/Security
11 | - AFNetworking/Serialization
12 | - AFNetworking/Reachability (4.0.1)
13 | - AFNetworking/Security (4.0.1)
14 | - AFNetworking/Serialization (4.0.1)
15 | - AFNetworking/UIKit (4.0.1):
16 | - AFNetworking/NSURLSession
17 | - SocketRocket (0.5.1)
18 |
19 | DEPENDENCIES:
20 | - AFNetworking (~> 4.0.1)
21 | - SocketRocket
22 |
23 | SPEC REPOS:
24 | https://github.com/CocoaPods/Specs.git:
25 | - AFNetworking
26 | - SocketRocket
27 |
28 | SPEC CHECKSUMS:
29 | AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
30 | SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531
31 |
32 | PODFILE CHECKSUM: c0c7e90e13164c9015675c3f74ff0ebdda48eb2a
33 |
34 | COCOAPODS: 1.9.3
35 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/AFNetworking/AFCompatibilityMacros.h:
--------------------------------------------------------------------------------
1 | // AFCompatibilityMacros.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #ifndef AFCompatibilityMacros_h
23 | #define AFCompatibilityMacros_h
24 |
25 | #ifdef API_AVAILABLE
26 | #define AF_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__)
27 | #else
28 | #define AF_API_AVAILABLE(...)
29 | #endif // API_AVAILABLE
30 |
31 | #ifdef API_UNAVAILABLE
32 | #define AF_API_UNAVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__)
33 | #else
34 | #define AF_API_UNAVAILABLE(...)
35 | #endif // API_UNAVAILABLE
36 |
37 | #if __has_warning("-Wunguarded-availability-new")
38 | #define AF_CAN_USE_AT_AVAILABLE 1
39 | #else
40 | #define AF_CAN_USE_AT_AVAILABLE 0
41 | #endif
42 |
43 | #if ((__IPHONE_OS_VERSION_MAX_ALLOWED && __IPHONE_OS_VERSION_MAX_ALLOWED < 100000) || (__MAC_OS_VERSION_MAX_ALLOWED && __MAC_OS_VERSION_MAX_ALLOWED < 101200) ||(__WATCH_OS_MAX_VERSION_ALLOWED && __WATCH_OS_MAX_VERSION_ALLOWED < 30000) ||(__TV_OS_MAX_VERSION_ALLOWED && __TV_OS_MAX_VERSION_ALLOWED < 100000))
44 | #define AF_CAN_INCLUDE_SESSION_TASK_METRICS 0
45 | #else
46 | #define AF_CAN_INCLUDE_SESSION_TASK_METRICS 1
47 | #endif
48 |
49 | #endif /* AFCompatibilityMacros_h */
50 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/AFNetworking/AFNetworkReachabilityManager.h:
--------------------------------------------------------------------------------
1 | // AFNetworkReachabilityManager.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #if !TARGET_OS_WATCH
25 | #import
26 |
27 | typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
28 | AFNetworkReachabilityStatusUnknown = -1,
29 | AFNetworkReachabilityStatusNotReachable = 0,
30 | AFNetworkReachabilityStatusReachableViaWWAN = 1,
31 | AFNetworkReachabilityStatusReachableViaWiFi = 2,
32 | };
33 |
34 | NS_ASSUME_NONNULL_BEGIN
35 |
36 | /**
37 | `AFNetworkReachabilityManager` monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
38 |
39 | Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
40 |
41 | See Apple's Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ )
42 |
43 | @warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined.
44 | */
45 | @interface AFNetworkReachabilityManager : NSObject
46 |
47 | /**
48 | The current network reachability status.
49 | */
50 | @property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
51 |
52 | /**
53 | Whether or not the network is currently reachable.
54 | */
55 | @property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;
56 |
57 | /**
58 | Whether or not the network is currently reachable via WWAN.
59 | */
60 | @property (readonly, nonatomic, assign, getter = isReachableViaWWAN) BOOL reachableViaWWAN;
61 |
62 | /**
63 | Whether or not the network is currently reachable via WiFi.
64 | */
65 | @property (readonly, nonatomic, assign, getter = isReachableViaWiFi) BOOL reachableViaWiFi;
66 |
67 | ///---------------------
68 | /// @name Initialization
69 | ///---------------------
70 |
71 | /**
72 | Returns the shared network reachability manager.
73 | */
74 | + (instancetype)sharedManager;
75 |
76 | /**
77 | Creates and returns a network reachability manager with the default socket address.
78 |
79 | @return An initialized network reachability manager, actively monitoring the default socket address.
80 | */
81 | + (instancetype)manager;
82 |
83 | /**
84 | Creates and returns a network reachability manager for the specified domain.
85 |
86 | @param domain The domain used to evaluate network reachability.
87 |
88 | @return An initialized network reachability manager, actively monitoring the specified domain.
89 | */
90 | + (instancetype)managerForDomain:(NSString *)domain;
91 |
92 | /**
93 | Creates and returns a network reachability manager for the socket address.
94 |
95 | @param address The socket address (`sockaddr_in6`) used to evaluate network reachability.
96 |
97 | @return An initialized network reachability manager, actively monitoring the specified socket address.
98 | */
99 | + (instancetype)managerForAddress:(const void *)address;
100 |
101 | /**
102 | Initializes an instance of a network reachability manager from the specified reachability object.
103 |
104 | @param reachability The reachability object to monitor.
105 |
106 | @return An initialized network reachability manager, actively monitoring the specified reachability.
107 | */
108 | - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability NS_DESIGNATED_INITIALIZER;
109 |
110 | /**
111 | * Unavailable initializer
112 | */
113 | + (instancetype)new NS_UNAVAILABLE;
114 |
115 | /**
116 | * Unavailable initializer
117 | */
118 | - (instancetype)init NS_UNAVAILABLE;
119 |
120 | ///--------------------------------------------------
121 | /// @name Starting & Stopping Reachability Monitoring
122 | ///--------------------------------------------------
123 |
124 | /**
125 | Starts monitoring for changes in network reachability status.
126 | */
127 | - (void)startMonitoring;
128 |
129 | /**
130 | Stops monitoring for changes in network reachability status.
131 | */
132 | - (void)stopMonitoring;
133 |
134 | ///-------------------------------------------------
135 | /// @name Getting Localized Reachability Description
136 | ///-------------------------------------------------
137 |
138 | /**
139 | Returns a localized string representation of the current network reachability status.
140 | */
141 | - (NSString *)localizedNetworkReachabilityStatusString;
142 |
143 | ///---------------------------------------------------
144 | /// @name Setting Network Reachability Change Callback
145 | ///---------------------------------------------------
146 |
147 | /**
148 | Sets a callback to be executed when the network availability of the `baseURL` host changes.
149 |
150 | @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the `baseURL`.
151 | */
152 | - (void)setReachabilityStatusChangeBlock:(nullable void (^)(AFNetworkReachabilityStatus status))block;
153 |
154 | @end
155 |
156 | ///----------------
157 | /// @name Constants
158 | ///----------------
159 |
160 | /**
161 | ## Network Reachability
162 |
163 | The following constants are provided by `AFNetworkReachabilityManager` as possible network reachability statuses.
164 |
165 | enum {
166 | AFNetworkReachabilityStatusUnknown,
167 | AFNetworkReachabilityStatusNotReachable,
168 | AFNetworkReachabilityStatusReachableViaWWAN,
169 | AFNetworkReachabilityStatusReachableViaWiFi,
170 | }
171 |
172 | `AFNetworkReachabilityStatusUnknown`
173 | The `baseURL` host reachability is not known.
174 |
175 | `AFNetworkReachabilityStatusNotReachable`
176 | The `baseURL` host cannot be reached.
177 |
178 | `AFNetworkReachabilityStatusReachableViaWWAN`
179 | The `baseURL` host can be reached via a cellular connection, such as EDGE or GPRS.
180 |
181 | `AFNetworkReachabilityStatusReachableViaWiFi`
182 | The `baseURL` host can be reached via a Wi-Fi connection.
183 |
184 | ### Keys for Notification UserInfo Dictionary
185 |
186 | Strings that are used as keys in a `userInfo` dictionary in a network reachability status change notification.
187 |
188 | `AFNetworkingReachabilityNotificationStatusItem`
189 | A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification.
190 | The corresponding value is an `NSNumber` object representing the `AFNetworkReachabilityStatus` value for the current reachability status.
191 | */
192 |
193 | ///--------------------
194 | /// @name Notifications
195 | ///--------------------
196 |
197 | /**
198 | Posted when network reachability changes.
199 | This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability.
200 |
201 | @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (`Prefix.pch`).
202 | */
203 | FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityDidChangeNotification;
204 | FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityNotificationStatusItem;
205 |
206 | ///--------------------
207 | /// @name Functions
208 | ///--------------------
209 |
210 | /**
211 | Returns a localized string representation of an `AFNetworkReachabilityStatus` value.
212 | */
213 | FOUNDATION_EXPORT NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status);
214 |
215 | NS_ASSUME_NONNULL_END
216 | #endif
217 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/AFNetworking/AFNetworking.h:
--------------------------------------------------------------------------------
1 | // AFNetworking.h
2 | //
3 | // Copyright (c) 2013 AFNetworking (http://afnetworking.com/)
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import
24 | #import
25 | #import
26 |
27 | #ifndef _AFNETWORKING_
28 | #define _AFNETWORKING_
29 |
30 | #import "AFURLRequestSerialization.h"
31 | #import "AFURLResponseSerialization.h"
32 | #import "AFSecurityPolicy.h"
33 |
34 | #if !TARGET_OS_WATCH
35 | #import "AFNetworkReachabilityManager.h"
36 | #endif
37 |
38 | #import "AFURLSessionManager.h"
39 | #import "AFHTTPSessionManager.h"
40 |
41 | #endif /* _AFNETWORKING_ */
42 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/AFNetworking/AFSecurityPolicy.h:
--------------------------------------------------------------------------------
1 | // AFSecurityPolicy.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 |
25 | typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
26 | AFSSLPinningModeNone,
27 | AFSSLPinningModePublicKey,
28 | AFSSLPinningModeCertificate,
29 | };
30 |
31 | /**
32 | `AFSecurityPolicy` evaluates server trust against pinned X.509 certificates and public keys over secure connections.
33 |
34 | Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.
35 | */
36 |
37 | NS_ASSUME_NONNULL_BEGIN
38 |
39 | @interface AFSecurityPolicy : NSObject
40 |
41 | /**
42 | The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`.
43 | */
44 | @property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
45 |
46 | /**
47 | The certificates used to evaluate server trust according to the SSL pinning mode.
48 |
49 | Note that if pinning is enabled, `evaluateServerTrust:forDomain:` will return true if any pinned certificate matches.
50 |
51 | @see policyWithPinningMode:withPinnedCertificates:
52 | */
53 | @property (nonatomic, strong, nullable) NSSet *pinnedCertificates;
54 |
55 | /**
56 | Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to `NO`.
57 | */
58 | @property (nonatomic, assign) BOOL allowInvalidCertificates;
59 |
60 | /**
61 | Whether or not to validate the domain name in the certificate's CN field. Defaults to `YES`.
62 | */
63 | @property (nonatomic, assign) BOOL validatesDomainName;
64 |
65 | ///-----------------------------------------
66 | /// @name Getting Certificates from the Bundle
67 | ///-----------------------------------------
68 |
69 | /**
70 | Returns any certificates included in the bundle. If you are using AFNetworking as an embedded framework, you must use this method to find the certificates you have included in your app bundle, and use them when creating your security policy by calling `policyWithPinningMode:withPinnedCertificates`.
71 |
72 | @return The certificates included in the given bundle.
73 | */
74 | + (NSSet *)certificatesInBundle:(NSBundle *)bundle;
75 |
76 | ///-----------------------------------------
77 | /// @name Getting Specific Security Policies
78 | ///-----------------------------------------
79 |
80 | /**
81 | Returns the shared default security policy, which does not allow invalid certificates, validates domain name, and does not validate against pinned certificates or public keys.
82 |
83 | @return The default security policy.
84 | */
85 | + (instancetype)defaultPolicy;
86 |
87 | ///---------------------
88 | /// @name Initialization
89 | ///---------------------
90 |
91 | /**
92 | Creates and returns a security policy with the specified pinning mode.
93 |
94 | Certificates with the `.cer` extension found in the main bundle will be pinned. If you want more control over which certificates are pinned, please use `policyWithPinningMode:withPinnedCertificates:` instead.
95 |
96 | @param pinningMode The SSL pinning mode.
97 |
98 | @return A new security policy.
99 |
100 | @see -policyWithPinningMode:withPinnedCertificates:
101 | */
102 | + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode;
103 |
104 | /**
105 | Creates and returns a security policy with the specified pinning mode.
106 |
107 | @param pinningMode The SSL pinning mode.
108 | @param pinnedCertificates The certificates to pin against.
109 |
110 | @return A new security policy.
111 |
112 | @see +certificatesInBundle:
113 | @see -pinnedCertificates
114 | */
115 | + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet *)pinnedCertificates;
116 |
117 | ///------------------------------
118 | /// @name Evaluating Server Trust
119 | ///------------------------------
120 |
121 | /**
122 | Whether or not the specified server trust should be accepted, based on the security policy.
123 |
124 | This method should be used when responding to an authentication challenge from a server.
125 |
126 | @param serverTrust The X.509 certificate trust of the server.
127 | @param domain The domain of serverTrust. If `nil`, the domain will not be validated.
128 |
129 | @return Whether or not to trust the server.
130 | */
131 | - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
132 | forDomain:(nullable NSString *)domain;
133 |
134 | @end
135 |
136 | NS_ASSUME_NONNULL_END
137 |
138 | ///----------------
139 | /// @name Constants
140 | ///----------------
141 |
142 | /**
143 | ## SSL Pinning Modes
144 |
145 | The following constants are provided by `AFSSLPinningMode` as possible SSL pinning modes.
146 |
147 | enum {
148 | AFSSLPinningModeNone,
149 | AFSSLPinningModePublicKey,
150 | AFSSLPinningModeCertificate,
151 | }
152 |
153 | `AFSSLPinningModeNone`
154 | Do not used pinned certificates to validate servers.
155 |
156 | `AFSSLPinningModePublicKey`
157 | Validate host certificates against public keys of pinned certificates.
158 |
159 | `AFSSLPinningModeCertificate`
160 | Validate host certificates against pinned certificates.
161 | */
162 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/)
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h:
--------------------------------------------------------------------------------
1 | // AFAutoPurgingImageCache.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 |
25 | #if TARGET_OS_IOS || TARGET_OS_TV
26 | #import
27 |
28 | NS_ASSUME_NONNULL_BEGIN
29 |
30 | /**
31 | The `AFImageCache` protocol defines a set of APIs for adding, removing and fetching images from a cache synchronously.
32 | */
33 | @protocol AFImageCache
34 |
35 | /**
36 | Adds the image to the cache with the given identifier.
37 |
38 | @param image The image to cache.
39 | @param identifier The unique identifier for the image in the cache.
40 | */
41 | - (void)addImage:(UIImage *)image withIdentifier:(NSString *)identifier;
42 |
43 | /**
44 | Removes the image from the cache matching the given identifier.
45 |
46 | @param identifier The unique identifier for the image in the cache.
47 |
48 | @return A BOOL indicating whether or not the image was removed from the cache.
49 | */
50 | - (BOOL)removeImageWithIdentifier:(NSString *)identifier;
51 |
52 | /**
53 | Removes all images from the cache.
54 |
55 | @return A BOOL indicating whether or not all images were removed from the cache.
56 | */
57 | - (BOOL)removeAllImages;
58 |
59 | /**
60 | Returns the image in the cache associated with the given identifier.
61 |
62 | @param identifier The unique identifier for the image in the cache.
63 |
64 | @return An image for the matching identifier, or nil.
65 | */
66 | - (nullable UIImage *)imageWithIdentifier:(NSString *)identifier;
67 | @end
68 |
69 |
70 | /**
71 | The `ImageRequestCache` protocol extends the `ImageCache` protocol by adding methods for adding, removing and fetching images from a cache given an `NSURLRequest` and additional identifier.
72 | */
73 | @protocol AFImageRequestCache
74 |
75 | /**
76 | Asks if the image should be cached using an identifier created from the request and additional identifier.
77 |
78 | @param image The image to be cached.
79 | @param request The unique URL request identifing the image asset.
80 | @param identifier The additional identifier to apply to the URL request to identify the image.
81 |
82 | @return A BOOL indicating whether or not the image should be added to the cache. YES will cache, NO will prevent caching.
83 | */
84 | - (BOOL)shouldCacheImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
85 |
86 | /**
87 | Adds the image to the cache using an identifier created from the request and additional identifier.
88 |
89 | @param image The image to cache.
90 | @param request The unique URL request identifing the image asset.
91 | @param identifier The additional identifier to apply to the URL request to identify the image.
92 | */
93 | - (void)addImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
94 |
95 | /**
96 | Removes the image from the cache using an identifier created from the request and additional identifier.
97 |
98 | @param request The unique URL request identifing the image asset.
99 | @param identifier The additional identifier to apply to the URL request to identify the image.
100 |
101 | @return A BOOL indicating whether or not all images were removed from the cache.
102 | */
103 | - (BOOL)removeImageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
104 |
105 | /**
106 | Returns the image from the cache associated with an identifier created from the request and additional identifier.
107 |
108 | @param request The unique URL request identifing the image asset.
109 | @param identifier The additional identifier to apply to the URL request to identify the image.
110 |
111 | @return An image for the matching request and identifier, or nil.
112 | */
113 | - (nullable UIImage *)imageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
114 |
115 | @end
116 |
117 | /**
118 | The `AutoPurgingImageCache` in an in-memory image cache used to store images up to a given memory capacity. When the memory capacity is reached, the image cache is sorted by last access date, then the oldest image is continuously purged until the preferred memory usage after purge is met. Each time an image is accessed through the cache, the internal access date of the image is updated.
119 | */
120 | @interface AFAutoPurgingImageCache : NSObject
121 |
122 | /**
123 | The total memory capacity of the cache in bytes.
124 | */
125 | @property (nonatomic, assign) UInt64 memoryCapacity;
126 |
127 | /**
128 | The preferred memory usage after purge in bytes. During a purge, images will be purged until the memory capacity drops below this limit.
129 | */
130 | @property (nonatomic, assign) UInt64 preferredMemoryUsageAfterPurge;
131 |
132 | /**
133 | The current total memory usage in bytes of all images stored within the cache.
134 | */
135 | @property (nonatomic, assign, readonly) UInt64 memoryUsage;
136 |
137 | /**
138 | Initialies the `AutoPurgingImageCache` instance with default values for memory capacity and preferred memory usage after purge limit. `memoryCapcity` defaults to `100 MB`. `preferredMemoryUsageAfterPurge` defaults to `60 MB`.
139 |
140 | @return The new `AutoPurgingImageCache` instance.
141 | */
142 | - (instancetype)init;
143 |
144 | /**
145 | Initialies the `AutoPurgingImageCache` instance with the given memory capacity and preferred memory usage
146 | after purge limit.
147 |
148 | @param memoryCapacity The total memory capacity of the cache in bytes.
149 | @param preferredMemoryCapacity The preferred memory usage after purge in bytes.
150 |
151 | @return The new `AutoPurgingImageCache` instance.
152 | */
153 | - (instancetype)initWithMemoryCapacity:(UInt64)memoryCapacity preferredMemoryCapacity:(UInt64)preferredMemoryCapacity;
154 |
155 | @end
156 |
157 | NS_ASSUME_NONNULL_END
158 |
159 | #endif
160 |
161 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.m:
--------------------------------------------------------------------------------
1 | // AFAutoPurgingImageCache.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #if TARGET_OS_IOS || TARGET_OS_TV
25 |
26 | #import "AFAutoPurgingImageCache.h"
27 |
28 | @interface AFCachedImage : NSObject
29 |
30 | @property (nonatomic, strong) UIImage *image;
31 | @property (nonatomic, copy) NSString *identifier;
32 | @property (nonatomic, assign) UInt64 totalBytes;
33 | @property (nonatomic, strong) NSDate *lastAccessDate;
34 | @property (nonatomic, assign) UInt64 currentMemoryUsage;
35 |
36 | @end
37 |
38 | @implementation AFCachedImage
39 |
40 | - (instancetype)initWithImage:(UIImage *)image identifier:(NSString *)identifier {
41 | if (self = [self init]) {
42 | self.image = image;
43 | self.identifier = identifier;
44 |
45 | CGSize imageSize = CGSizeMake(image.size.width * image.scale, image.size.height * image.scale);
46 | CGFloat bytesPerPixel = 4.0;
47 | CGFloat bytesPerSize = imageSize.width * imageSize.height;
48 | self.totalBytes = (UInt64)bytesPerPixel * (UInt64)bytesPerSize;
49 | self.lastAccessDate = [NSDate date];
50 | }
51 | return self;
52 | }
53 |
54 | - (UIImage *)accessImage {
55 | self.lastAccessDate = [NSDate date];
56 | return self.image;
57 | }
58 |
59 | - (NSString *)description {
60 | NSString *descriptionString = [NSString stringWithFormat:@"Idenfitier: %@ lastAccessDate: %@ ", self.identifier, self.lastAccessDate];
61 | return descriptionString;
62 |
63 | }
64 |
65 | @end
66 |
67 | @interface AFAutoPurgingImageCache ()
68 | @property (nonatomic, strong) NSMutableDictionary *cachedImages;
69 | @property (nonatomic, assign) UInt64 currentMemoryUsage;
70 | @property (nonatomic, strong) dispatch_queue_t synchronizationQueue;
71 | @end
72 |
73 | @implementation AFAutoPurgingImageCache
74 |
75 | - (instancetype)init {
76 | return [self initWithMemoryCapacity:100 * 1024 * 1024 preferredMemoryCapacity:60 * 1024 * 1024];
77 | }
78 |
79 | - (instancetype)initWithMemoryCapacity:(UInt64)memoryCapacity preferredMemoryCapacity:(UInt64)preferredMemoryCapacity {
80 | if (self = [super init]) {
81 | self.memoryCapacity = memoryCapacity;
82 | self.preferredMemoryUsageAfterPurge = preferredMemoryCapacity;
83 | self.cachedImages = [[NSMutableDictionary alloc] init];
84 |
85 | NSString *queueName = [NSString stringWithFormat:@"com.alamofire.autopurgingimagecache-%@", [[NSUUID UUID] UUIDString]];
86 | self.synchronizationQueue = dispatch_queue_create([queueName cStringUsingEncoding:NSASCIIStringEncoding], DISPATCH_QUEUE_CONCURRENT);
87 |
88 | [[NSNotificationCenter defaultCenter]
89 | addObserver:self
90 | selector:@selector(removeAllImages)
91 | name:UIApplicationDidReceiveMemoryWarningNotification
92 | object:nil];
93 |
94 | }
95 | return self;
96 | }
97 |
98 | - (void)dealloc {
99 | [[NSNotificationCenter defaultCenter] removeObserver:self];
100 | }
101 |
102 | - (UInt64)memoryUsage {
103 | __block UInt64 result = 0;
104 | dispatch_sync(self.synchronizationQueue, ^{
105 | result = self.currentMemoryUsage;
106 | });
107 | return result;
108 | }
109 |
110 | - (void)addImage:(UIImage *)image withIdentifier:(NSString *)identifier {
111 | dispatch_barrier_async(self.synchronizationQueue, ^{
112 | AFCachedImage *cacheImage = [[AFCachedImage alloc] initWithImage:image identifier:identifier];
113 |
114 | AFCachedImage *previousCachedImage = self.cachedImages[identifier];
115 | if (previousCachedImage != nil) {
116 | self.currentMemoryUsage -= previousCachedImage.totalBytes;
117 | }
118 |
119 | self.cachedImages[identifier] = cacheImage;
120 | self.currentMemoryUsage += cacheImage.totalBytes;
121 | });
122 |
123 | dispatch_barrier_async(self.synchronizationQueue, ^{
124 | if (self.currentMemoryUsage > self.memoryCapacity) {
125 | UInt64 bytesToPurge = self.currentMemoryUsage - self.preferredMemoryUsageAfterPurge;
126 | NSMutableArray *sortedImages = [NSMutableArray arrayWithArray:self.cachedImages.allValues];
127 | NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastAccessDate"
128 | ascending:YES];
129 | [sortedImages sortUsingDescriptors:@[sortDescriptor]];
130 |
131 | UInt64 bytesPurged = 0;
132 |
133 | for (AFCachedImage *cachedImage in sortedImages) {
134 | [self.cachedImages removeObjectForKey:cachedImage.identifier];
135 | bytesPurged += cachedImage.totalBytes;
136 | if (bytesPurged >= bytesToPurge) {
137 | break;
138 | }
139 | }
140 | self.currentMemoryUsage -= bytesPurged;
141 | }
142 | });
143 | }
144 |
145 | - (BOOL)removeImageWithIdentifier:(NSString *)identifier {
146 | __block BOOL removed = NO;
147 | dispatch_barrier_sync(self.synchronizationQueue, ^{
148 | AFCachedImage *cachedImage = self.cachedImages[identifier];
149 | if (cachedImage != nil) {
150 | [self.cachedImages removeObjectForKey:identifier];
151 | self.currentMemoryUsage -= cachedImage.totalBytes;
152 | removed = YES;
153 | }
154 | });
155 | return removed;
156 | }
157 |
158 | - (BOOL)removeAllImages {
159 | __block BOOL removed = NO;
160 | dispatch_barrier_sync(self.synchronizationQueue, ^{
161 | if (self.cachedImages.count > 0) {
162 | [self.cachedImages removeAllObjects];
163 | self.currentMemoryUsage = 0;
164 | removed = YES;
165 | }
166 | });
167 | return removed;
168 | }
169 |
170 | - (nullable UIImage *)imageWithIdentifier:(NSString *)identifier {
171 | __block UIImage *image = nil;
172 | dispatch_sync(self.synchronizationQueue, ^{
173 | AFCachedImage *cachedImage = self.cachedImages[identifier];
174 | image = [cachedImage accessImage];
175 | });
176 | return image;
177 | }
178 |
179 | - (void)addImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(NSString *)identifier {
180 | [self addImage:image withIdentifier:[self imageCacheKeyFromURLRequest:request withAdditionalIdentifier:identifier]];
181 | }
182 |
183 | - (BOOL)removeImageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(NSString *)identifier {
184 | return [self removeImageWithIdentifier:[self imageCacheKeyFromURLRequest:request withAdditionalIdentifier:identifier]];
185 | }
186 |
187 | - (nullable UIImage *)imageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(NSString *)identifier {
188 | return [self imageWithIdentifier:[self imageCacheKeyFromURLRequest:request withAdditionalIdentifier:identifier]];
189 | }
190 |
191 | - (NSString *)imageCacheKeyFromURLRequest:(NSURLRequest *)request withAdditionalIdentifier:(NSString *)additionalIdentifier {
192 | NSString *key = request.URL.absoluteString;
193 | if (additionalIdentifier != nil) {
194 | key = [key stringByAppendingString:additionalIdentifier];
195 | }
196 | return key;
197 | }
198 |
199 | - (BOOL)shouldCacheImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier {
200 | return YES;
201 | }
202 |
203 | @end
204 |
205 | #endif
206 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/AFImageDownloader.h:
--------------------------------------------------------------------------------
1 | // AFImageDownloader.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #if TARGET_OS_IOS || TARGET_OS_TV
25 |
26 | #import
27 | #import "AFAutoPurgingImageCache.h"
28 | #import "AFHTTPSessionManager.h"
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | typedef NS_ENUM(NSInteger, AFImageDownloadPrioritization) {
33 | AFImageDownloadPrioritizationFIFO,
34 | AFImageDownloadPrioritizationLIFO
35 | };
36 |
37 | /**
38 | The `AFImageDownloadReceipt` is an object vended by the `AFImageDownloader` when starting a data task. It can be used to cancel active tasks running on the `AFImageDownloader` session. As a general rule, image data tasks should be cancelled using the `AFImageDownloadReceipt` instead of calling `cancel` directly on the `task` itself. The `AFImageDownloader` is optimized to handle duplicate task scenarios as well as pending versus active downloads.
39 | */
40 | @interface AFImageDownloadReceipt : NSObject
41 |
42 | /**
43 | The data task created by the `AFImageDownloader`.
44 | */
45 | @property (nonatomic, strong) NSURLSessionDataTask *task;
46 |
47 | /**
48 | The unique identifier for the success and failure blocks when duplicate requests are made.
49 | */
50 | @property (nonatomic, strong) NSUUID *receiptID;
51 | @end
52 |
53 | /** The `AFImageDownloader` class is responsible for downloading images in parallel on a prioritized queue. Incoming downloads are added to the front or back of the queue depending on the download prioritization. Each downloaded image is cached in the underlying `NSURLCache` as well as the in-memory image cache. By default, any download request with a cached image equivalent in the image cache will automatically be served the cached image representation.
54 | */
55 | @interface AFImageDownloader : NSObject
56 |
57 | /**
58 | The image cache used to store all downloaded images in. `AFAutoPurgingImageCache` by default.
59 | */
60 | @property (nonatomic, strong, nullable) id imageCache;
61 |
62 | /**
63 | The `AFHTTPSessionManager` used to download images. By default, this is configured with an `AFImageResponseSerializer`, and a shared `NSURLCache` for all image downloads.
64 | */
65 | @property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
66 |
67 | /**
68 | Defines the order prioritization of incoming download requests being inserted into the queue. `AFImageDownloadPrioritizationFIFO` by default.
69 | */
70 | @property (nonatomic, assign) AFImageDownloadPrioritization downloadPrioritization;
71 |
72 | /**
73 | The shared default instance of `AFImageDownloader` initialized with default values.
74 | */
75 | + (instancetype)defaultInstance;
76 |
77 | /**
78 | Creates a default `NSURLCache` with common usage parameter values.
79 |
80 | @returns The default `NSURLCache` instance.
81 | */
82 | + (NSURLCache *)defaultURLCache;
83 |
84 | /**
85 | The default `NSURLSessionConfiguration` with common usage parameter values.
86 | */
87 | + (NSURLSessionConfiguration *)defaultURLSessionConfiguration;
88 |
89 | /**
90 | Default initializer
91 |
92 | @return An instance of `AFImageDownloader` initialized with default values.
93 | */
94 | - (instancetype)init;
95 |
96 | /**
97 | Initializer with specific `URLSessionConfiguration`
98 |
99 | @param configuration The `NSURLSessionConfiguration` to be be used
100 |
101 | @return An instance of `AFImageDownloader` initialized with default values and custom `NSURLSessionConfiguration`
102 | */
103 | - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration;
104 |
105 | /**
106 | Initializes the `AFImageDownloader` instance with the given session manager, download prioritization, maximum active download count and image cache.
107 |
108 | @param sessionManager The session manager to use to download images.
109 | @param downloadPrioritization The download prioritization of the download queue.
110 | @param maximumActiveDownloads The maximum number of active downloads allowed at any given time. Recommend `4`.
111 | @param imageCache The image cache used to store all downloaded images in.
112 |
113 | @return The new `AFImageDownloader` instance.
114 | */
115 | - (instancetype)initWithSessionManager:(AFHTTPSessionManager *)sessionManager
116 | downloadPrioritization:(AFImageDownloadPrioritization)downloadPrioritization
117 | maximumActiveDownloads:(NSInteger)maximumActiveDownloads
118 | imageCache:(nullable id )imageCache;
119 |
120 | /**
121 | Creates a data task using the `sessionManager` instance for the specified URL request.
122 |
123 | If the same data task is already in the queue or currently being downloaded, the success and failure blocks are
124 | appended to the already existing task. Once the task completes, all success or failure blocks attached to the
125 | task are executed in the order they were added.
126 |
127 | @param request The URL request.
128 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`.
129 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
130 |
131 | @return The image download receipt for the data task if available. `nil` if the image is stored in the cache.
132 | cache and the URL request cache policy allows the cache to be used.
133 | */
134 | - (nullable AFImageDownloadReceipt *)downloadImageForURLRequest:(NSURLRequest *)request
135 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *responseObject))success
136 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure;
137 |
138 | /**
139 | Creates a data task using the `sessionManager` instance for the specified URL request.
140 |
141 | If the same data task is already in the queue or currently being downloaded, the success and failure blocks are
142 | appended to the already existing task. Once the task completes, all success or failure blocks attached to the
143 | task are executed in the order they were added.
144 |
145 | @param request The URL request.
146 | @param receiptID The identifier to use for the download receipt that will be created for this request. This must be a unique identifier that does not represent any other request.
147 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`.
148 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
149 |
150 | @return The image download receipt for the data task if available. `nil` if the image is stored in the cache.
151 | cache and the URL request cache policy allows the cache to be used.
152 | */
153 | - (nullable AFImageDownloadReceipt *)downloadImageForURLRequest:(NSURLRequest *)request
154 | withReceiptID:(NSUUID *)receiptID
155 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *responseObject))success
156 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure;
157 |
158 | /**
159 | Cancels the data task in the receipt by removing the corresponding success and failure blocks and cancelling the data task if necessary.
160 |
161 | If the data task is pending in the queue, it will be cancelled if no other success and failure blocks are registered with the data task. If the data task is currently executing or is already completed, the success and failure blocks are removed and will not be called when the task finishes.
162 |
163 | @param imageDownloadReceipt The image download receipt to cancel.
164 | */
165 | - (void)cancelTaskForImageDownloadReceipt:(AFImageDownloadReceipt *)imageDownloadReceipt;
166 |
167 | @end
168 |
169 | #endif
170 |
171 | NS_ASSUME_NONNULL_END
172 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h:
--------------------------------------------------------------------------------
1 | // AFNetworkActivityIndicatorManager.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | /**
33 | `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a session task has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero.
34 |
35 | You should enable the shared instance of `AFNetworkActivityIndicatorManager` when your application finishes launching. In `AppDelegate application:didFinishLaunchingWithOptions:` you can do so with the following code:
36 |
37 | [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
38 |
39 | By setting `enabled` to `YES` for `sharedManager`, the network activity indicator will show and hide automatically as requests start and finish. You should not ever need to call `incrementActivityCount` or `decrementActivityCount` yourself.
40 |
41 | See the Apple Human Interface Guidelines section about the Network Activity Indicator for more information:
42 | http://developer.apple.com/library/iOS/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW44
43 | */
44 | NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.")
45 | @interface AFNetworkActivityIndicatorManager : NSObject
46 |
47 | /**
48 | A Boolean value indicating whether the manager is enabled.
49 |
50 | If YES, the manager will change status bar network activity indicator according to network operation notifications it receives. The default value is NO.
51 | */
52 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled;
53 |
54 | /**
55 | A Boolean value indicating whether the network activity indicator manager is currently active.
56 | */
57 | @property (readonly, nonatomic, assign, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;
58 |
59 | /**
60 | A time interval indicating the minimum duration of networking activity that should occur before the activity indicator is displayed. The default value 1 second. If the network activity indicator should be displayed immediately when network activity occurs, this value should be set to 0 seconds.
61 |
62 | Apple's HIG describes the following:
63 |
64 | > Display the network activity indicator to provide feedback when your app accesses the network for more than a couple of seconds. If the operation finishes sooner than that, you don’t have to show the network activity indicator, because the indicator is likely to disappear before users notice its presence.
65 |
66 | */
67 | @property (nonatomic, assign) NSTimeInterval activationDelay;
68 |
69 | /**
70 | A time interval indicating the duration of time of no networking activity required before the activity indicator is disabled. This allows for continuous display of the network activity indicator across multiple requests. The default value is 0.17 seconds.
71 | */
72 |
73 | @property (nonatomic, assign) NSTimeInterval completionDelay;
74 |
75 | /**
76 | Returns the shared network activity indicator manager object for the system.
77 |
78 | @return The systemwide network activity indicator manager.
79 | */
80 | + (instancetype)sharedManager;
81 |
82 | /**
83 | Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator.
84 | */
85 | - (void)incrementActivityCount;
86 |
87 | /**
88 | Decrements the number of active network requests. If this number becomes zero after decrementing, this will stop animating the status bar network activity indicator.
89 | */
90 | - (void)decrementActivityCount;
91 |
92 | /**
93 | Set the a custom method to be executed when the network activity indicator manager should be hidden/shown. By default, this is null, and the UIApplication Network Activity Indicator will be managed automatically. If this block is set, it is the responsiblity of the caller to manager the network activity indicator going forward.
94 |
95 | @param block A block to be executed when the network activity indicator status changes.
96 | */
97 | - (void)setNetworkingActivityActionWithBlock:(nullable void (^)(BOOL networkActivityIndicatorVisible))block;
98 |
99 | @end
100 |
101 | NS_ASSUME_NONNULL_END
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.m:
--------------------------------------------------------------------------------
1 | // AFNetworkActivityIndicatorManager.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "AFNetworkActivityIndicatorManager.h"
23 |
24 | #if TARGET_OS_IOS
25 | #import "AFURLSessionManager.h"
26 |
27 | typedef NS_ENUM(NSInteger, AFNetworkActivityManagerState) {
28 | AFNetworkActivityManagerStateNotActive,
29 | AFNetworkActivityManagerStateDelayingStart,
30 | AFNetworkActivityManagerStateActive,
31 | AFNetworkActivityManagerStateDelayingEnd
32 | };
33 |
34 | static NSTimeInterval const kDefaultAFNetworkActivityManagerActivationDelay = 1.0;
35 | static NSTimeInterval const kDefaultAFNetworkActivityManagerCompletionDelay = 0.17;
36 |
37 | static NSURLRequest * AFNetworkRequestFromNotification(NSNotification *notification) {
38 | if ([[notification object] respondsToSelector:@selector(originalRequest)]) {
39 | return [(NSURLSessionTask *)[notification object] originalRequest];
40 | } else {
41 | return nil;
42 | }
43 | }
44 |
45 | typedef void (^AFNetworkActivityActionBlock)(BOOL networkActivityIndicatorVisible);
46 |
47 | @interface AFNetworkActivityIndicatorManager ()
48 | @property (readwrite, nonatomic, assign) NSInteger activityCount;
49 | @property (readwrite, nonatomic, strong) NSTimer *activationDelayTimer;
50 | @property (readwrite, nonatomic, strong) NSTimer *completionDelayTimer;
51 | @property (readonly, nonatomic, getter = isNetworkActivityOccurring) BOOL networkActivityOccurring;
52 | @property (nonatomic, copy) AFNetworkActivityActionBlock networkActivityActionBlock;
53 | @property (nonatomic, assign) AFNetworkActivityManagerState currentState;
54 | @property (nonatomic, assign, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;
55 |
56 | - (void)updateCurrentStateForNetworkActivityChange;
57 | @end
58 |
59 | @implementation AFNetworkActivityIndicatorManager
60 |
61 | + (instancetype)sharedManager {
62 | static AFNetworkActivityIndicatorManager *_sharedManager = nil;
63 | static dispatch_once_t oncePredicate;
64 | dispatch_once(&oncePredicate, ^{
65 | _sharedManager = [[self alloc] init];
66 | });
67 |
68 | return _sharedManager;
69 | }
70 |
71 | - (instancetype)init {
72 | self = [super init];
73 | if (!self) {
74 | return nil;
75 | }
76 | self.currentState = AFNetworkActivityManagerStateNotActive;
77 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidStart:) name:AFNetworkingTaskDidResumeNotification object:nil];
78 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidFinish:) name:AFNetworkingTaskDidSuspendNotification object:nil];
79 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequestDidFinish:) name:AFNetworkingTaskDidCompleteNotification object:nil];
80 | self.activationDelay = kDefaultAFNetworkActivityManagerActivationDelay;
81 | self.completionDelay = kDefaultAFNetworkActivityManagerCompletionDelay;
82 |
83 | return self;
84 | }
85 |
86 | - (void)dealloc {
87 | [[NSNotificationCenter defaultCenter] removeObserver:self];
88 |
89 | [_activationDelayTimer invalidate];
90 | [_completionDelayTimer invalidate];
91 | }
92 |
93 | - (void)setEnabled:(BOOL)enabled {
94 | _enabled = enabled;
95 | if (enabled == NO) {
96 | [self setCurrentState:AFNetworkActivityManagerStateNotActive];
97 | }
98 | }
99 |
100 | - (void)setNetworkingActivityActionWithBlock:(void (^)(BOOL networkActivityIndicatorVisible))block {
101 | self.networkActivityActionBlock = block;
102 | }
103 |
104 | - (BOOL)isNetworkActivityOccurring {
105 | @synchronized(self) {
106 | return self.activityCount > 0;
107 | }
108 | }
109 |
110 | - (void)setNetworkActivityIndicatorVisible:(BOOL)networkActivityIndicatorVisible {
111 | if (_networkActivityIndicatorVisible != networkActivityIndicatorVisible) {
112 | @synchronized(self) {
113 | _networkActivityIndicatorVisible = networkActivityIndicatorVisible;
114 | }
115 | if (self.networkActivityActionBlock) {
116 | self.networkActivityActionBlock(networkActivityIndicatorVisible);
117 | } else {
118 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:networkActivityIndicatorVisible];
119 | }
120 | }
121 | }
122 |
123 |
124 | - (void)incrementActivityCount {
125 | @synchronized(self) {
126 | self.activityCount++;
127 | }
128 | dispatch_async(dispatch_get_main_queue(), ^{
129 | [self updateCurrentStateForNetworkActivityChange];
130 | });
131 | }
132 |
133 | - (void)decrementActivityCount {
134 | @synchronized(self) {
135 | self.activityCount = MAX(_activityCount - 1, 0);
136 | }
137 | dispatch_async(dispatch_get_main_queue(), ^{
138 | [self updateCurrentStateForNetworkActivityChange];
139 | });
140 | }
141 |
142 | - (void)networkRequestDidStart:(NSNotification *)notification {
143 | if ([AFNetworkRequestFromNotification(notification) URL]) {
144 | [self incrementActivityCount];
145 | }
146 | }
147 |
148 | - (void)networkRequestDidFinish:(NSNotification *)notification {
149 | if ([AFNetworkRequestFromNotification(notification) URL]) {
150 | [self decrementActivityCount];
151 | }
152 | }
153 |
154 | #pragma mark - Internal State Management
155 | - (void)setCurrentState:(AFNetworkActivityManagerState)currentState {
156 | @synchronized(self) {
157 | if (_currentState != currentState) {
158 | _currentState = currentState;
159 | switch (currentState) {
160 | case AFNetworkActivityManagerStateNotActive:
161 | [self cancelActivationDelayTimer];
162 | [self cancelCompletionDelayTimer];
163 | [self setNetworkActivityIndicatorVisible:NO];
164 | break;
165 | case AFNetworkActivityManagerStateDelayingStart:
166 | [self startActivationDelayTimer];
167 | break;
168 | case AFNetworkActivityManagerStateActive:
169 | [self cancelCompletionDelayTimer];
170 | [self setNetworkActivityIndicatorVisible:YES];
171 | break;
172 | case AFNetworkActivityManagerStateDelayingEnd:
173 | [self startCompletionDelayTimer];
174 | break;
175 | }
176 | }
177 | }
178 | }
179 |
180 | - (void)updateCurrentStateForNetworkActivityChange {
181 | if (self.enabled) {
182 | switch (self.currentState) {
183 | case AFNetworkActivityManagerStateNotActive:
184 | if (self.isNetworkActivityOccurring) {
185 | [self setCurrentState:AFNetworkActivityManagerStateDelayingStart];
186 | }
187 | break;
188 | case AFNetworkActivityManagerStateDelayingStart:
189 | //No op. Let the delay timer finish out.
190 | break;
191 | case AFNetworkActivityManagerStateActive:
192 | if (!self.isNetworkActivityOccurring) {
193 | [self setCurrentState:AFNetworkActivityManagerStateDelayingEnd];
194 | }
195 | break;
196 | case AFNetworkActivityManagerStateDelayingEnd:
197 | if (self.isNetworkActivityOccurring) {
198 | [self setCurrentState:AFNetworkActivityManagerStateActive];
199 | }
200 | break;
201 | }
202 | }
203 | }
204 |
205 | - (void)startActivationDelayTimer {
206 | self.activationDelayTimer = [NSTimer
207 | timerWithTimeInterval:self.activationDelay target:self selector:@selector(activationDelayTimerFired) userInfo:nil repeats:NO];
208 | [[NSRunLoop mainRunLoop] addTimer:self.activationDelayTimer forMode:NSRunLoopCommonModes];
209 | }
210 |
211 | - (void)activationDelayTimerFired {
212 | if (self.networkActivityOccurring) {
213 | [self setCurrentState:AFNetworkActivityManagerStateActive];
214 | } else {
215 | [self setCurrentState:AFNetworkActivityManagerStateNotActive];
216 | }
217 | }
218 |
219 | - (void)startCompletionDelayTimer {
220 | [self.completionDelayTimer invalidate];
221 | self.completionDelayTimer = [NSTimer timerWithTimeInterval:self.completionDelay target:self selector:@selector(completionDelayTimerFired) userInfo:nil repeats:NO];
222 | [[NSRunLoop mainRunLoop] addTimer:self.completionDelayTimer forMode:NSRunLoopCommonModes];
223 | }
224 |
225 | - (void)completionDelayTimerFired {
226 | [self setCurrentState:AFNetworkActivityManagerStateNotActive];
227 | }
228 |
229 | - (void)cancelActivationDelayTimer {
230 | [self.activationDelayTimer invalidate];
231 | }
232 |
233 | - (void)cancelCompletionDelayTimer {
234 | [self.completionDelayTimer invalidate];
235 | }
236 |
237 | @end
238 |
239 | #endif
240 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIActivityIndicatorView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | /**
31 | This category adds methods to the UIKit framework's `UIActivityIndicatorView` class. The methods in this category provide support for automatically starting and stopping animation depending on the loading state of a session task.
32 | */
33 | @interface UIActivityIndicatorView (AFNetworking)
34 |
35 | ///----------------------------------
36 | /// @name Animating for Session Tasks
37 | ///----------------------------------
38 |
39 | /**
40 | Binds the animating state to the state of the specified task.
41 |
42 | @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled.
43 | */
44 | - (void)setAnimatingWithStateOfTask:(nullable NSURLSessionTask *)task;
45 |
46 | @end
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIActivityIndicatorView+AFNetworking.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "UIActivityIndicatorView+AFNetworking.h"
23 | #import
24 |
25 | #if TARGET_OS_IOS || TARGET_OS_TV
26 |
27 | #import "AFURLSessionManager.h"
28 |
29 | @interface AFActivityIndicatorViewNotificationObserver : NSObject
30 | @property (readonly, nonatomic, weak) UIActivityIndicatorView *activityIndicatorView;
31 | - (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView;
32 |
33 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task;
34 |
35 | @end
36 |
37 | @implementation UIActivityIndicatorView (AFNetworking)
38 |
39 | - (AFActivityIndicatorViewNotificationObserver *)af_notificationObserver {
40 | AFActivityIndicatorViewNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver));
41 | if (notificationObserver == nil) {
42 | notificationObserver = [[AFActivityIndicatorViewNotificationObserver alloc] initWithActivityIndicatorView:self];
43 | objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
44 | }
45 | return notificationObserver;
46 | }
47 |
48 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
49 | [[self af_notificationObserver] setAnimatingWithStateOfTask:task];
50 | }
51 |
52 | @end
53 |
54 | @implementation AFActivityIndicatorViewNotificationObserver
55 |
56 | - (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView
57 | {
58 | self = [super init];
59 | if (self) {
60 | _activityIndicatorView = activityIndicatorView;
61 | }
62 | return self;
63 | }
64 |
65 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
66 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
67 |
68 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
69 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
70 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
71 |
72 | if (task) {
73 | if (task.state != NSURLSessionTaskStateCompleted) {
74 | UIActivityIndicatorView *activityIndicatorView = self.activityIndicatorView;
75 | if (task.state == NSURLSessionTaskStateRunning) {
76 | [activityIndicatorView startAnimating];
77 | } else {
78 | [activityIndicatorView stopAnimating];
79 | }
80 |
81 | [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidResumeNotification object:task];
82 | [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidCompleteNotification object:task];
83 | [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task];
84 | }
85 | }
86 | }
87 |
88 | #pragma mark -
89 |
90 | - (void)af_startAnimating {
91 | dispatch_async(dispatch_get_main_queue(), ^{
92 | [self.activityIndicatorView startAnimating];
93 | });
94 | }
95 |
96 | - (void)af_stopAnimating {
97 | dispatch_async(dispatch_get_main_queue(), ^{
98 | [self.activityIndicatorView stopAnimating];
99 | });
100 | }
101 |
102 | #pragma mark -
103 |
104 | - (void)dealloc {
105 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
106 |
107 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
108 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
109 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
110 | }
111 |
112 | @end
113 |
114 | #endif
115 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIButton+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIButton+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | @class AFImageDownloader;
33 |
34 | /**
35 | This category adds methods to the UIKit framework's `UIButton` class. The methods in this category provide support for loading remote images and background images asynchronously from a URL.
36 |
37 | @warning Compound values for control `state` (such as `UIControlStateHighlighted | UIControlStateDisabled`) are unsupported.
38 | */
39 | @interface UIButton (AFNetworking)
40 |
41 | ///------------------------------------
42 | /// @name Accessing the Image Downloader
43 | ///------------------------------------
44 |
45 | /**
46 | Set the shared image downloader used to download images.
47 |
48 | @param imageDownloader The shared image downloader used to download images.
49 | */
50 | + (void)setSharedImageDownloader:(AFImageDownloader *)imageDownloader;
51 |
52 | /**
53 | The shared image downloader used to download images.
54 | */
55 | + (AFImageDownloader *)sharedImageDownloader;
56 |
57 | ///--------------------
58 | /// @name Setting Image
59 | ///--------------------
60 |
61 | /**
62 | Asynchronously downloads an image from the specified URL, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
63 |
64 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
65 |
66 | @param state The control state.
67 | @param url The URL used for the image request.
68 | */
69 | - (void)setImageForState:(UIControlState)state
70 | withURL:(NSURL *)url;
71 |
72 | /**
73 | Asynchronously downloads an image from the specified URL, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
74 |
75 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
76 |
77 | @param state The control state.
78 | @param url The URL used for the image request.
79 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the button will not change its image until the image request finishes.
80 | */
81 | - (void)setImageForState:(UIControlState)state
82 | withURL:(NSURL *)url
83 | placeholderImage:(nullable UIImage *)placeholderImage;
84 |
85 | /**
86 | Asynchronously downloads an image from the specified URL request, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
87 |
88 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
89 |
90 | If a success block is specified, it is the responsibility of the block to set the image of the button before returning. If no success block is specified, the default behavior of setting the image with `setImage:forState:` is applied.
91 |
92 | @param state The control state.
93 | @param urlRequest The URL request used for the image request.
94 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the button will not change its image until the image request finishes.
95 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`.
96 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
97 | */
98 | - (void)setImageForState:(UIControlState)state
99 | withURLRequest:(NSURLRequest *)urlRequest
100 | placeholderImage:(nullable UIImage *)placeholderImage
101 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success
102 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure;
103 |
104 |
105 | ///-------------------------------
106 | /// @name Setting Background Image
107 | ///-------------------------------
108 |
109 | /**
110 | Asynchronously downloads an image from the specified URL, and sets it as the background image for the specified state once the request is finished. Any previous background image request for the receiver will be cancelled.
111 |
112 | If the background image is cached locally, the background image is set immediately, otherwise the specified placeholder background image will be set immediately, and then the remote background image will be set once the request is finished.
113 |
114 | @param state The control state.
115 | @param url The URL used for the background image request.
116 | */
117 | - (void)setBackgroundImageForState:(UIControlState)state
118 | withURL:(NSURL *)url;
119 |
120 | /**
121 | Asynchronously downloads an image from the specified URL, and sets it as the background image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
122 |
123 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
124 |
125 | @param state The control state.
126 | @param url The URL used for the background image request.
127 | @param placeholderImage The background image to be set initially, until the background image request finishes. If `nil`, the button will not change its background image until the background image request finishes.
128 | */
129 | - (void)setBackgroundImageForState:(UIControlState)state
130 | withURL:(NSURL *)url
131 | placeholderImage:(nullable UIImage *)placeholderImage;
132 |
133 | /**
134 | Asynchronously downloads an image from the specified URL request, and sets it as the image for the specified state once the request is finished. Any previous image request for the receiver will be cancelled.
135 |
136 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
137 |
138 | If a success block is specified, it is the responsibility of the block to set the image of the button before returning. If no success block is specified, the default behavior of setting the image with `setBackgroundImage:forState:` is applied.
139 |
140 | @param state The control state.
141 | @param urlRequest The URL request used for the image request.
142 | @param placeholderImage The background image to be set initially, until the background image request finishes. If `nil`, the button will not change its background image until the background image request finishes.
143 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`.
144 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
145 | */
146 | - (void)setBackgroundImageForState:(UIControlState)state
147 | withURLRequest:(NSURLRequest *)urlRequest
148 | placeholderImage:(nullable UIImage *)placeholderImage
149 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success
150 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure;
151 |
152 |
153 | ///------------------------------
154 | /// @name Canceling Image Loading
155 | ///------------------------------
156 |
157 | /**
158 | Cancels any executing image task for the specified control state of the receiver, if one exists.
159 |
160 | @param state The control state.
161 | */
162 | - (void)cancelImageDownloadTaskForState:(UIControlState)state;
163 |
164 | /**
165 | Cancels any executing background image task for the specified control state of the receiver, if one exists.
166 |
167 | @param state The control state.
168 | */
169 | - (void)cancelBackgroundImageDownloadTaskForState:(UIControlState)state;
170 |
171 | @end
172 |
173 | NS_ASSUME_NONNULL_END
174 |
175 | #endif
176 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIImageView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | @class AFImageDownloader;
33 |
34 | /**
35 | This category adds methods to the UIKit framework's `UIImageView` class. The methods in this category provide support for loading remote images asynchronously from a URL.
36 | */
37 | @interface UIImageView (AFNetworking)
38 |
39 | ///------------------------------------
40 | /// @name Accessing the Image Downloader
41 | ///------------------------------------
42 |
43 | /**
44 | Set the shared image downloader used to download images.
45 |
46 | @param imageDownloader The shared image downloader used to download images.
47 | */
48 | + (void)setSharedImageDownloader:(AFImageDownloader *)imageDownloader;
49 |
50 | /**
51 | The shared image downloader used to download images.
52 | */
53 | + (AFImageDownloader *)sharedImageDownloader;
54 |
55 | ///--------------------
56 | /// @name Setting Image
57 | ///--------------------
58 |
59 | /**
60 | Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.
61 |
62 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
63 |
64 | By default, URL requests have a `Accept` header field value of "image / *", a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
65 |
66 | @param url The URL used for the image request.
67 | */
68 | - (void)setImageWithURL:(NSURL *)url;
69 |
70 | /**
71 | Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.
72 |
73 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
74 |
75 | By default, URL requests have a `Accept` header field value of "image / *", a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
76 |
77 | @param url The URL used for the image request.
78 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
79 | */
80 | - (void)setImageWithURL:(NSURL *)url
81 | placeholderImage:(nullable UIImage *)placeholderImage;
82 |
83 | /**
84 | Asynchronously downloads an image from the specified URL request, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.
85 |
86 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
87 |
88 | If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is applied.
89 |
90 | @param urlRequest The URL request used for the image request.
91 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
92 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`.
93 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
94 | */
95 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
96 | placeholderImage:(nullable UIImage *)placeholderImage
97 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success
98 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure;
99 |
100 | /**
101 | Cancels any executing image operation for the receiver, if one exists.
102 | */
103 | - (void)cancelImageDownloadTask;
104 |
105 | @end
106 |
107 | NS_ASSUME_NONNULL_END
108 |
109 | #endif
110 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIImageView+AFNetworking.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "UIImageView+AFNetworking.h"
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import "AFImageDownloader.h"
29 |
30 | @interface UIImageView (_AFNetworking)
31 | @property (readwrite, nonatomic, strong, setter = af_setActiveImageDownloadReceipt:) AFImageDownloadReceipt *af_activeImageDownloadReceipt;
32 | @end
33 |
34 | @implementation UIImageView (_AFNetworking)
35 |
36 | - (AFImageDownloadReceipt *)af_activeImageDownloadReceipt {
37 | return (AFImageDownloadReceipt *)objc_getAssociatedObject(self, @selector(af_activeImageDownloadReceipt));
38 | }
39 |
40 | - (void)af_setActiveImageDownloadReceipt:(AFImageDownloadReceipt *)imageDownloadReceipt {
41 | objc_setAssociatedObject(self, @selector(af_activeImageDownloadReceipt), imageDownloadReceipt, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
42 | }
43 |
44 | @end
45 |
46 | #pragma mark -
47 |
48 | @implementation UIImageView (AFNetworking)
49 |
50 | + (AFImageDownloader *)sharedImageDownloader {
51 | return objc_getAssociatedObject([UIImageView class], @selector(sharedImageDownloader)) ?: [AFImageDownloader defaultInstance];
52 | }
53 |
54 | + (void)setSharedImageDownloader:(AFImageDownloader *)imageDownloader {
55 | objc_setAssociatedObject([UIImageView class], @selector(sharedImageDownloader), imageDownloader, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
56 | }
57 |
58 | #pragma mark -
59 |
60 | - (void)setImageWithURL:(NSURL *)url {
61 | [self setImageWithURL:url placeholderImage:nil];
62 | }
63 |
64 | - (void)setImageWithURL:(NSURL *)url
65 | placeholderImage:(UIImage *)placeholderImage
66 | {
67 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
68 | [request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
69 |
70 | [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
71 | }
72 |
73 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
74 | placeholderImage:(UIImage *)placeholderImage
75 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success
76 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure
77 | {
78 | if ([urlRequest URL] == nil) {
79 | self.image = placeholderImage;
80 | if (failure) {
81 | NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil];
82 | failure(urlRequest, nil, error);
83 | }
84 | return;
85 | }
86 |
87 | if ([self isActiveTaskURLEqualToURLRequest:urlRequest]) {
88 | return;
89 | }
90 |
91 | [self cancelImageDownloadTask];
92 |
93 | AFImageDownloader *downloader = [[self class] sharedImageDownloader];
94 | id imageCache = downloader.imageCache;
95 |
96 | //Use the image from the image cache if it exists
97 | UIImage *cachedImage = [imageCache imageforRequest:urlRequest withAdditionalIdentifier:nil];
98 | if (cachedImage) {
99 | if (success) {
100 | success(urlRequest, nil, cachedImage);
101 | } else {
102 | self.image = cachedImage;
103 | }
104 | [self clearActiveDownloadInformation];
105 | } else {
106 | if (placeholderImage) {
107 | self.image = placeholderImage;
108 | }
109 |
110 | __weak __typeof(self)weakSelf = self;
111 | NSUUID *downloadID = [NSUUID UUID];
112 | AFImageDownloadReceipt *receipt;
113 | receipt = [downloader
114 | downloadImageForURLRequest:urlRequest
115 | withReceiptID:downloadID
116 | success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull responseObject) {
117 | __strong __typeof(weakSelf)strongSelf = weakSelf;
118 | if ([strongSelf.af_activeImageDownloadReceipt.receiptID isEqual:downloadID]) {
119 | if (success) {
120 | success(request, response, responseObject);
121 | } else if (responseObject) {
122 | strongSelf.image = responseObject;
123 | }
124 | [strongSelf clearActiveDownloadInformation];
125 | }
126 |
127 | }
128 | failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
129 | __strong __typeof(weakSelf)strongSelf = weakSelf;
130 | if ([strongSelf.af_activeImageDownloadReceipt.receiptID isEqual:downloadID]) {
131 | if (failure) {
132 | failure(request, response, error);
133 | }
134 | [strongSelf clearActiveDownloadInformation];
135 | }
136 | }];
137 |
138 | self.af_activeImageDownloadReceipt = receipt;
139 | }
140 | }
141 |
142 | - (void)cancelImageDownloadTask {
143 | if (self.af_activeImageDownloadReceipt != nil) {
144 | [[self.class sharedImageDownloader] cancelTaskForImageDownloadReceipt:self.af_activeImageDownloadReceipt];
145 | [self clearActiveDownloadInformation];
146 | }
147 | }
148 |
149 | - (void)clearActiveDownloadInformation {
150 | self.af_activeImageDownloadReceipt = nil;
151 | }
152 |
153 | - (BOOL)isActiveTaskURLEqualToURLRequest:(NSURLRequest *)urlRequest {
154 | return [self.af_activeImageDownloadReceipt.task.originalRequest.URL.absoluteString isEqualToString:urlRequest.URL.absoluteString];
155 | }
156 |
157 | @end
158 |
159 | #endif
160 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIKit+AFNetworking.h
2 | //
3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import
24 |
25 | #ifndef _UIKIT_AFNETWORKING_
26 | #define _UIKIT_AFNETWORKING_
27 |
28 | #if TARGET_OS_IOS || TARGET_OS_TV
29 | #import "AFAutoPurgingImageCache.h"
30 | #import "AFImageDownloader.h"
31 | #import "UIActivityIndicatorView+AFNetworking.h"
32 | #import "UIButton+AFNetworking.h"
33 | #import "UIImageView+AFNetworking.h"
34 | #import "UIProgressView+AFNetworking.h"
35 | #endif
36 |
37 | #if TARGET_OS_IOS
38 | #import "AFNetworkActivityIndicatorManager.h"
39 | #import "UIRefreshControl+AFNetworking.h"
40 | #import "WKWebView+AFNetworking.h"
41 | #endif
42 |
43 | #endif /* _UIKIT_AFNETWORKING_ */
44 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIProgressView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 |
33 | /**
34 | This category adds methods to the UIKit framework's `UIProgressView` class. The methods in this category provide support for binding the progress to the upload and download progress of a session task.
35 | */
36 | @interface UIProgressView (AFNetworking)
37 |
38 | ///------------------------------------
39 | /// @name Setting Session Task Progress
40 | ///------------------------------------
41 |
42 | /**
43 | Binds the progress to the upload progress of the specified session task.
44 |
45 | @param task The session task.
46 | @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
47 | */
48 | - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task
49 | animated:(BOOL)animated;
50 |
51 | /**
52 | Binds the progress to the download progress of the specified session task.
53 |
54 | @param task The session task.
55 | @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
56 | */
57 | - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task
58 | animated:(BOOL)animated;
59 |
60 | @end
61 |
62 | NS_ASSUME_NONNULL_END
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIProgressView+AFNetworking.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "UIProgressView+AFNetworking.h"
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import "AFURLSessionManager.h"
29 |
30 | static void * AFTaskCountOfBytesSentContext = &AFTaskCountOfBytesSentContext;
31 | static void * AFTaskCountOfBytesReceivedContext = &AFTaskCountOfBytesReceivedContext;
32 |
33 | #pragma mark -
34 |
35 | @implementation UIProgressView (AFNetworking)
36 |
37 | - (BOOL)af_uploadProgressAnimated {
38 | return [(NSNumber *)objc_getAssociatedObject(self, @selector(af_uploadProgressAnimated)) boolValue];
39 | }
40 |
41 | - (void)af_setUploadProgressAnimated:(BOOL)animated {
42 | objc_setAssociatedObject(self, @selector(af_uploadProgressAnimated), @(animated), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
43 | }
44 |
45 | - (BOOL)af_downloadProgressAnimated {
46 | return [(NSNumber *)objc_getAssociatedObject(self, @selector(af_downloadProgressAnimated)) boolValue];
47 | }
48 |
49 | - (void)af_setDownloadProgressAnimated:(BOOL)animated {
50 | objc_setAssociatedObject(self, @selector(af_downloadProgressAnimated), @(animated), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
51 | }
52 |
53 | #pragma mark -
54 |
55 | - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task
56 | animated:(BOOL)animated
57 | {
58 | if (task.state == NSURLSessionTaskStateCompleted) {
59 | return;
60 | }
61 |
62 | [task addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesSentContext];
63 | [task addObserver:self forKeyPath:@"countOfBytesSent" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesSentContext];
64 |
65 | [self af_setUploadProgressAnimated:animated];
66 | }
67 |
68 | - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task
69 | animated:(BOOL)animated
70 | {
71 | if (task.state == NSURLSessionTaskStateCompleted) {
72 | return;
73 | }
74 |
75 | [task addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesReceivedContext];
76 | [task addObserver:self forKeyPath:@"countOfBytesReceived" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesReceivedContext];
77 |
78 | [self af_setDownloadProgressAnimated:animated];
79 | }
80 |
81 | #pragma mark - NSKeyValueObserving
82 |
83 | - (void)observeValueForKeyPath:(NSString *)keyPath
84 | ofObject:(id)object
85 | change:(__unused NSDictionary *)change
86 | context:(void *)context
87 | {
88 | if (context == AFTaskCountOfBytesSentContext || context == AFTaskCountOfBytesReceivedContext) {
89 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesSent))]) {
90 | if ([object countOfBytesExpectedToSend] > 0) {
91 | dispatch_async(dispatch_get_main_queue(), ^{
92 | [self setProgress:[object countOfBytesSent] / ([object countOfBytesExpectedToSend] * 1.0f) animated:self.af_uploadProgressAnimated];
93 | });
94 | }
95 | }
96 |
97 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) {
98 | if ([object countOfBytesExpectedToReceive] > 0) {
99 | dispatch_async(dispatch_get_main_queue(), ^{
100 | [self setProgress:[object countOfBytesReceived] / ([object countOfBytesExpectedToReceive] * 1.0f) animated:self.af_downloadProgressAnimated];
101 | });
102 | }
103 | }
104 |
105 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(state))]) {
106 | if ([(NSURLSessionTask *)object state] == NSURLSessionTaskStateCompleted) {
107 | @try {
108 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(state))];
109 |
110 | if (context == AFTaskCountOfBytesSentContext) {
111 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesSent))];
112 | }
113 |
114 | if (context == AFTaskCountOfBytesReceivedContext) {
115 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesReceived))];
116 | }
117 | }
118 | @catch (NSException * __unused exception) {}
119 | }
120 | }
121 | }
122 | }
123 |
124 | @end
125 |
126 | #endif
127 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIRefreshControl+AFNetworking.m
2 | //
3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import
24 |
25 | #import
26 |
27 | #if TARGET_OS_IOS
28 |
29 | #import
30 |
31 | NS_ASSUME_NONNULL_BEGIN
32 |
33 | /**
34 | This category adds methods to the UIKit framework's `UIRefreshControl` class. The methods in this category provide support for automatically beginning and ending refreshing depending on the loading state of a session task.
35 | */
36 | @interface UIRefreshControl (AFNetworking)
37 |
38 | ///-----------------------------------
39 | /// @name Refreshing for Session Tasks
40 | ///-----------------------------------
41 |
42 | /**
43 | Binds the refreshing state to the state of the specified task.
44 |
45 | @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled.
46 | */
47 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task;
48 |
49 | @end
50 |
51 | NS_ASSUME_NONNULL_END
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIRefreshControl+AFNetworking.m
2 | //
3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import "UIRefreshControl+AFNetworking.h"
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import "AFURLSessionManager.h"
29 |
30 | @interface AFRefreshControlNotificationObserver : NSObject
31 | @property (readonly, nonatomic, weak) UIRefreshControl *refreshControl;
32 | - (instancetype)initWithActivityRefreshControl:(UIRefreshControl *)refreshControl;
33 |
34 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task;
35 |
36 | @end
37 |
38 | @implementation UIRefreshControl (AFNetworking)
39 |
40 | - (AFRefreshControlNotificationObserver *)af_notificationObserver {
41 | AFRefreshControlNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver));
42 | if (notificationObserver == nil) {
43 | notificationObserver = [[AFRefreshControlNotificationObserver alloc] initWithActivityRefreshControl:self];
44 | objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
45 | }
46 | return notificationObserver;
47 | }
48 |
49 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task {
50 | [[self af_notificationObserver] setRefreshingWithStateOfTask:task];
51 | }
52 |
53 | @end
54 |
55 | @implementation AFRefreshControlNotificationObserver
56 |
57 | - (instancetype)initWithActivityRefreshControl:(UIRefreshControl *)refreshControl
58 | {
59 | self = [super init];
60 | if (self) {
61 | _refreshControl = refreshControl;
62 | }
63 | return self;
64 | }
65 |
66 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task {
67 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
68 |
69 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
70 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
71 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
72 |
73 | if (task) {
74 | UIRefreshControl *refreshControl = self.refreshControl;
75 | if (task.state == NSURLSessionTaskStateRunning) {
76 | [refreshControl beginRefreshing];
77 |
78 | [notificationCenter addObserver:self selector:@selector(af_beginRefreshing) name:AFNetworkingTaskDidResumeNotification object:task];
79 | [notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidCompleteNotification object:task];
80 | [notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidSuspendNotification object:task];
81 | } else {
82 | [refreshControl endRefreshing];
83 | }
84 | }
85 | }
86 |
87 | #pragma mark -
88 |
89 | - (void)af_beginRefreshing {
90 | dispatch_async(dispatch_get_main_queue(), ^{
91 | [self.refreshControl beginRefreshing];
92 | });
93 | }
94 |
95 | - (void)af_endRefreshing {
96 | dispatch_async(dispatch_get_main_queue(), ^{
97 | [self.refreshControl endRefreshing];
98 | });
99 | }
100 |
101 | #pragma mark -
102 |
103 | - (void)dealloc {
104 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
105 |
106 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
107 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
108 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
109 | }
110 |
111 | @end
112 |
113 | #endif
114 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/WKWebView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // WkWebView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import
29 | #import
30 |
31 | NS_ASSUME_NONNULL_BEGIN
32 |
33 | @class AFHTTPSessionManager;
34 |
35 | @interface WKWebView (AFNetworking)
36 |
37 | /**
38 | The session manager used to download all request
39 | */
40 | @property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
41 |
42 | /**
43 | Asynchronously loads the specified request.
44 |
45 | @param request A URL request identifying the location of the content to load. This must not be `nil`.
46 | @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`.
47 | @param progress A progress object monitoring the current download progress.
48 | @param success A block object to be executed when the request finishes loading successfully. This block returns the HTML string to be loaded by the web view, and takes two arguments: the response, and the response string.
49 | @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred.
50 | */
51 | - (void)loadRequest:(NSURLRequest *)request
52 | navigation:(WKNavigation * _Nonnull)navigation
53 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
54 | success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success
55 | failure:(nullable void (^)(NSError *error))failure;
56 |
57 | /**
58 | Asynchronously loads the data associated with a particular request with a specified MIME type and text encoding.
59 |
60 | @param request A URL request identifying the location of the content to load. This must not be `nil`.
61 | @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`.
62 | @param MIMEType The MIME type of the content. Defaults to the content type of the response if not specified.
63 | @param textEncodingName The IANA encoding name, as in `utf-8` or `utf-16`. Defaults to the response text encoding if not specified.
64 | @param progress A progress object monitoring the current download progress.
65 | @param success A block object to be executed when the request finishes loading successfully. This block returns the data to be loaded by the web view and takes two arguments: the response, and the downloaded data.
66 | @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred.
67 | */
68 | - (void)loadRequest:(NSURLRequest *)request
69 | navigation:(WKNavigation * _Nonnull)navigation
70 | MIMEType:(nullable NSString *)MIMEType
71 | textEncodingName:(nullable NSString *)textEncodingName
72 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
73 | success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success
74 | failure:(nullable void (^)(NSError *error))failure;
75 |
76 | @end
77 |
78 | NS_ASSUME_NONNULL_END
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/Pods/AFNetworking/UIKit+AFNetworking/WKWebView+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // WkWebView+AFNetworking.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "WKWebView+AFNetworking.h"
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import "AFHTTPSessionManager.h"
29 | #import "AFURLResponseSerialization.h"
30 | #import "AFURLRequestSerialization.h"
31 |
32 | @interface WKWebView (_AFNetworking)
33 | @property (readwrite, nonatomic, strong, setter = af_setURLSessionTask:) NSURLSessionDataTask *af_URLSessionTask;
34 | @end
35 |
36 | @implementation WKWebView (_AFNetworking)
37 |
38 | - (NSURLSessionDataTask *)af_URLSessionTask {
39 | return (NSURLSessionDataTask *)objc_getAssociatedObject(self, @selector(af_URLSessionTask));
40 | }
41 |
42 | - (void)af_setURLSessionTask:(NSURLSessionDataTask *)af_URLSessionTask {
43 | objc_setAssociatedObject(self, @selector(af_URLSessionTask), af_URLSessionTask, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
44 | }
45 |
46 | @end
47 |
48 | #pragma mark -
49 |
50 | @implementation WKWebView (AFNetworking)
51 |
52 | - (AFHTTPSessionManager *)sessionManager {
53 | static AFHTTPSessionManager *_af_defaultHTTPSessionManager = nil;
54 | static dispatch_once_t onceToken;
55 | dispatch_once(&onceToken, ^{
56 | _af_defaultHTTPSessionManager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
57 | _af_defaultHTTPSessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
58 | _af_defaultHTTPSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
59 | });
60 |
61 | return objc_getAssociatedObject(self, @selector(sessionManager)) ?: _af_defaultHTTPSessionManager;
62 | }
63 |
64 | - (void)setSessionManager:(AFHTTPSessionManager *)sessionManager {
65 | objc_setAssociatedObject(self, @selector(sessionManager), sessionManager, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
66 | }
67 |
68 | - (AFHTTPResponseSerializer *)responseSerializer {
69 | static AFHTTPResponseSerializer *_af_defaultResponseSerializer = nil;
70 | static dispatch_once_t onceToken;
71 | dispatch_once(&onceToken, ^{
72 | _af_defaultResponseSerializer = [AFHTTPResponseSerializer serializer];
73 | });
74 |
75 | return objc_getAssociatedObject(self, @selector(responseSerializer)) ?: _af_defaultResponseSerializer;
76 | }
77 |
78 | - (void)setResponseSerializer:(AFHTTPResponseSerializer *)responseSerializer {
79 | objc_setAssociatedObject(self, @selector(responseSerializer), responseSerializer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
80 | }
81 |
82 | #pragma mark -
83 |
84 | - (void)loadRequest:(NSURLRequest *)request
85 | navigation:(WKNavigation * _Nonnull)navigation
86 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
87 | success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success
88 | failure:(nullable void (^)(NSError *error))failure {
89 | [self loadRequest:request navigation:navigation MIMEType:nil textEncodingName:nil progress:progress success:^NSData * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSData * _Nonnull data) {
90 | NSStringEncoding stringEncoding = NSUTF8StringEncoding;
91 | if (response.textEncodingName) {
92 | CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName);
93 | if (encoding != kCFStringEncodingInvalidId) {
94 | stringEncoding = CFStringConvertEncodingToNSStringEncoding(encoding);
95 | }
96 | }
97 |
98 | NSString *string = [[NSString alloc] initWithData:data encoding:stringEncoding];
99 | if (success) {
100 | string = success(response, string);
101 | }
102 |
103 | return [string dataUsingEncoding:stringEncoding];
104 | } failure:failure];
105 | }
106 |
107 | - (void)loadRequest:(NSURLRequest *)request
108 | navigation:(WKNavigation * _Nonnull)navigation
109 | MIMEType:(nullable NSString *)MIMEType
110 | textEncodingName:(nullable NSString *)textEncodingName
111 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
112 | success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success
113 | failure:(nullable void (^)(NSError *error))failure {
114 | NSParameterAssert(request);
115 |
116 | if (self.af_URLSessionTask.state == NSURLSessionTaskStateRunning || self.af_URLSessionTask.state == NSURLSessionTaskStateSuspended) {
117 | [self.af_URLSessionTask cancel];
118 | }
119 | self.af_URLSessionTask = nil;
120 |
121 | __weak __typeof(self)weakSelf = self;
122 | __block NSURLSessionDataTask *dataTask;
123 | __strong __typeof(weakSelf) strongSelf = weakSelf;
124 | __strong __typeof(weakSelf.navigationDelegate) strongSelfDelegate = strongSelf.navigationDelegate;
125 | dataTask = [self.sessionManager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
126 | if (error) {
127 | if (failure) {
128 | failure(error);
129 | }
130 | } else {
131 | if (success) {
132 | success((NSHTTPURLResponse *)response, responseObject);
133 | }
134 | [strongSelf loadData:responseObject MIMEType:MIMEType characterEncodingName:textEncodingName baseURL:[dataTask.currentRequest URL]];
135 |
136 | if ([strongSelfDelegate respondsToSelector:@selector(webView:didFinishNavigation:)]) {
137 | [strongSelfDelegate webView:strongSelf didFinishNavigation:navigation];
138 | }
139 | }
140 | }];
141 | self.af_URLSessionTask = dataTask;
142 | if (progress != nil) {
143 | *progress = [self.sessionManager downloadProgressForTask:dataTask];
144 | }
145 | [self.af_URLSessionTask resume];
146 |
147 | if ([strongSelfDelegate respondsToSelector:@selector(webView:didStartProvisionalNavigation:)]) {
148 | [strongSelfDelegate webView:self didStartProvisionalNavigation:navigation];
149 | }
150 | }
151 |
152 | @end
153 |
154 | #endif
155 |
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFAutoPurgingImageCache.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFCompatibilityMacros.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFCompatibilityMacros.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFHTTPSessionManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFHTTPSessionManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFImageDownloader.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/AFImageDownloader.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFNetworkActivityIndicatorManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFNetworkReachabilityManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFNetworkReachabilityManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFSecurityPolicy.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFSecurityPolicy.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFURLRequestSerialization.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFURLRequestSerialization.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFURLResponseSerialization.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFURLResponseSerialization.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/AFURLSessionManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFURLSessionManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/UIActivityIndicatorView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/UIButton+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIButton+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/UIImageView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/UIKit+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/UIProgressView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/UIRefreshControl+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/AFNetworking/WKWebView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/WKWebView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/SocketRocket/SRWebSocket.h:
--------------------------------------------------------------------------------
1 | ../../../SocketRocket/SocketRocket/SRWebSocket.h
--------------------------------------------------------------------------------
/Pods/Headers/Private/SocketRocket/SocketRocket.h:
--------------------------------------------------------------------------------
1 | ../../../SocketRocket/SocketRocket/SocketRocket.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFAutoPurgingImageCache.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFCompatibilityMacros.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFCompatibilityMacros.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFHTTPSessionManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFHTTPSessionManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFImageDownloader.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/AFImageDownloader.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFNetworkActivityIndicatorManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFNetworkReachabilityManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFNetworkReachabilityManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFSecurityPolicy.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFSecurityPolicy.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFURLRequestSerialization.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFURLRequestSerialization.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFURLResponseSerialization.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFURLResponseSerialization.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/AFURLSessionManager.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/AFNetworking/AFURLSessionManager.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/UIActivityIndicatorView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/UIButton+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIButton+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/UIImageView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/UIKit+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/UIProgressView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/UIRefreshControl+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/AFNetworking/WKWebView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | ../../../AFNetworking/UIKit+AFNetworking/WKWebView+AFNetworking.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/SocketRocket/SRWebSocket.h:
--------------------------------------------------------------------------------
1 | ../../../SocketRocket/SocketRocket/SRWebSocket.h
--------------------------------------------------------------------------------
/Pods/Headers/Public/SocketRocket/SocketRocket.h:
--------------------------------------------------------------------------------
1 | ../../../SocketRocket/SocketRocket/SocketRocket.h
--------------------------------------------------------------------------------
/Pods/Manifest.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - AFNetworking (4.0.1):
3 | - AFNetworking/NSURLSession (= 4.0.1)
4 | - AFNetworking/Reachability (= 4.0.1)
5 | - AFNetworking/Security (= 4.0.1)
6 | - AFNetworking/Serialization (= 4.0.1)
7 | - AFNetworking/UIKit (= 4.0.1)
8 | - AFNetworking/NSURLSession (4.0.1):
9 | - AFNetworking/Reachability
10 | - AFNetworking/Security
11 | - AFNetworking/Serialization
12 | - AFNetworking/Reachability (4.0.1)
13 | - AFNetworking/Security (4.0.1)
14 | - AFNetworking/Serialization (4.0.1)
15 | - AFNetworking/UIKit (4.0.1):
16 | - AFNetworking/NSURLSession
17 | - SocketRocket (0.5.1)
18 |
19 | DEPENDENCIES:
20 | - AFNetworking (~> 4.0.1)
21 | - SocketRocket
22 |
23 | SPEC REPOS:
24 | https://github.com/CocoaPods/Specs.git:
25 | - AFNetworking
26 | - SocketRocket
27 |
28 | SPEC CHECKSUMS:
29 | AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
30 | SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531
31 |
32 | PODFILE CHECKSUM: c0c7e90e13164c9015675c3f74ff0ebdda48eb2a
33 |
34 | COCOAPODS: 1.9.3
35 |
--------------------------------------------------------------------------------
/Pods/SocketRocket/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Copyright 2012 Square Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 |
16 |
--------------------------------------------------------------------------------
/Pods/SocketRocket/README.rst:
--------------------------------------------------------------------------------
1 | SocketRocket Objective-C WebSocket Client (beta)
2 | ================================================
3 | A conforming WebSocket (`RFC 6455 `_)
4 | client library.
5 |
6 | `Test results for SocketRocket here `_.
7 | You can compare to what `modern browsers look like here
8 | `_.
9 |
10 | SocketRocket currently conforms to all ~300 of `Autobahn
11 | `_'s fuzzing tests (aside from
12 | two UTF-8 ones where it is merely *non-strict*. tests 6.4.2 and 6.4.4)
13 |
14 | Features/Design
15 | ---------------
16 | - TLS (wss) support. It uses CFStream so we get this for *free*
17 | - Uses NSStream/CFNetworking. Earlier implementations used ``dispatch_io``,
18 | however, this proved to be make TLS nearly impossible. Also I wanted this to
19 | work in iOS 4.x. (SocketRocket only supports 5.0 and above now)
20 | - Uses ARC. It uses the 4.0 compatible subset (no weak refs).
21 | - Seems to perform quite well
22 | - Parallel architecture. Most of the work is done in background worker queues.
23 | - Delegate-based. Had older versions that could use blocks too, but I felt it
24 | didn't blend well with retain cycles and just objective C in general.
25 |
26 | Changes
27 | -------
28 |
29 | v0.3.1-beta2 - 2013-01-12
30 | `````````````````````````
31 |
32 | - Stability fix for ``closeWithCode:reason:`` (Thanks @michaelpetrov!)
33 | - Actually clean up the NSStreams and remove them from their runloops
34 | - ``_SRRunLoopThread``'s ``main`` wasn't correctly wrapped with
35 | ``@autoreleasepool``
36 |
37 | v0.3.1-beta1 - 2013-01-12
38 | `````````````````````````
39 |
40 | - Cleaned up GCD so OS_OBJECT_USE_OBJC_RETAIN_RELEASE is optional
41 | - Removed deprecated ``dispatch_get_current_queue`` in favor of ``dispatch_queue_set_specific`` and ``dispatch_get_specific``
42 | - Dropping support for iOS 4.0 (it may still work)
43 |
44 |
45 | Installing (iOS)
46 | ----------------
47 | There's a few options. Choose one, or just figure it out
48 |
49 | - You can copy all the files in the SocketRocket group into your app.
50 | - Include SocketRocket as a subproject and use libSocketRocket
51 |
52 | If you do this, you must add -ObjC to your "other linker flags" option
53 |
54 | - For OS X you will have to repackage make a .framework target. I will take
55 | contributions. Message me if you are interested.
56 |
57 |
58 | Depending on how you configure your project you may need to ``#import`` either
59 | ```` or ``"SRWebSocket.h"``
60 |
61 | Framework Dependencies
62 | ``````````````````````
63 | Your .app must be linked against the following frameworks/dylibs
64 |
65 | - libicucore.dylib
66 | - CFNetwork.framework
67 | - Security.framework
68 | - Foundation.framework
69 |
70 | Installing (OS X)
71 | -----------------
72 | SocketRocket now has (64-bit only) OS X support. ``SocketRocket.framework``
73 | inside Xcode project is for OS X only. It should be identical in function aside
74 | from the unicode validation. ICU isn't shipped with OS X which is what the
75 | original implementation used for unicode validation. The workaround is much
76 | more rudimentary and less robust.
77 |
78 | 1. Add SocketRocket.xcodeproj as either a subproject of your app or in your workspace.
79 | 2. Add ``SocketRocket.framework`` to the link libraries
80 | 3. If you don't have a "copy files" step for ``Framework``, create one
81 | 4. Add ``SocketRocket.framework`` to the "copy files" step.
82 |
83 | API
84 | ---
85 | The classes
86 |
87 | ``SRWebSocket``
88 | ```````````````
89 | The Web Socket.
90 |
91 | .. note:: ``SRWebSocket`` will retain itself between ``-(void)open`` and when it
92 | closes, errors, or fails. This is similar to how ``NSURLConnection`` behaves.
93 | (unlike ``NSURLConnection``, ``SRWebSocket`` won't retain the delegate)
94 |
95 | What you need to know
96 |
97 | .. code-block:: objective-c
98 |
99 | @interface SRWebSocket : NSObject
100 |
101 | // Make it with this
102 | - (id)initWithURLRequest:(NSURLRequest *)request;
103 |
104 | // Set this before opening
105 | @property (nonatomic, assign) id delegate;
106 |
107 | - (void)open;
108 |
109 | // Close it with this
110 | - (void)close;
111 |
112 | // Send a UTF8 String or Data
113 | - (void)send:(id)data;
114 |
115 | @end
116 |
117 | ``SRWebSocketDelegate``
118 | ```````````````````````
119 | You implement this
120 |
121 | .. code-block:: objective-c
122 |
123 | @protocol SRWebSocketDelegate
124 |
125 | - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
126 |
127 | @optional
128 |
129 | - (void)webSocketDidOpen:(SRWebSocket *)webSocket;
130 | - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
131 | - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
132 |
133 | @end
134 |
135 | Known Issues/Server Todo's
136 | --------------------------
137 | - Needs auth delegates (like in NSURLConnection)
138 | - Move the streams off the main runloop (most of the work is backgrounded uses
139 | GCD, but I just haven't gotten around to moving it off the main loop since I
140 | converted it from dispatch_io)
141 | - Re-implement server. I removed an existing implementation as well because it
142 | wasn't being used and I wasn't super happy with the interface. Will revisit
143 | this.
144 | - Separate framer and client logic. This will make it nicer when having a
145 | server.
146 |
147 | Testing
148 | -------
149 | Included are setup scripts for the python testing environment. It comes
150 | packaged with vitualenv so all the dependencies are installed in userland.
151 |
152 | To run the short test from the command line, run::
153 |
154 | make test
155 |
156 | To run all the tests, run::
157 |
158 | make test_all
159 |
160 | The short tests don't include the performance tests. (the test harness is
161 | actually the bottleneck, not SocketRocket).
162 |
163 | The first time this is run, it may take a while to install the dependencies. It
164 | will be smooth sailing after that. After the test runs the makefile will open
165 | the results page in your browser. If nothing comes up, you failed. Working on
166 | making this interface a bit nicer.
167 |
168 | To run from the app, choose the ``SocketRocket`` target and run the test action
169 | (``cmd+u``). It runs the same thing, but makes it easier to debug. There is
170 | some serious pre/post hooks in the Test action. You can edit it to customize
171 | behavior.
172 |
173 | .. note:: Xcode only up to version 4.4 is currently supported for the test
174 | harness
175 |
176 | TestChat Demo Application
177 | -------------------------
178 | SocketRocket includes a demo app, TestChat. It will "chat" with a listening
179 | websocket on port 9900.
180 |
181 | It's a simple project. Uses storyboard. Storyboard is sweet.
182 |
183 |
184 | TestChat Server
185 | ```````````````
186 | We've included a small server for the chat app. It has a simple function.
187 | It will take a message and broadcast it to all other connected clients.
188 |
189 | We have to get some dependencies. We also want to reuse the virtualenv we made
190 | when we ran the tests. If you haven't run the tests yet, go into the
191 | SocketRocket root directory and type::
192 |
193 | make test
194 |
195 | This will set up your `virtualenv `_.
196 | Now, in your terminal::
197 |
198 | source .env/bin/activate
199 | pip install git+https://github.com/tornadoweb/tornado.git
200 |
201 | In the same terminal session, start the chatroom server::
202 |
203 | python TestChatServer/py/chatroom.py
204 |
205 | There's also a Go implementation (with the latest weekly) where you can::
206 |
207 | cd TestChatServer/go
208 | go run chatroom.go
209 |
210 | Chatting
211 | ````````
212 | Now, start TestChat.app (just run the target in the Xcode project). If you had
213 | it started already you can hit the refresh button to reconnect. It should say
214 | "Connected!" on top.
215 |
216 | To talk with the app, open up your browser to `http://localhost:9000 `_ and
217 | start chatting.
218 |
219 |
220 | WebSocket Server Implementation Recommendations
221 | -----------------------------------------------
222 | SocketRocket has been used with the following libraries:
223 |
224 | - `Tornado `_
225 | - Go's `WebSocket package `_ or Gorilla's `version `_
226 | - `Autobahn `_ (using its fuzzing
227 | client)
228 |
229 | The Tornado one is dirt simple and works like a charm. (`IPython notebook
230 | `_ uses it
231 | too). It's much easier to configure handlers and routes than in
232 | Autobahn/twisted.
233 |
234 | As far as Go's goes, it works in my limited testing. I much prefer go's
235 | concurrency model as well. Try it! You may like it.
236 | It could use some more control over things such as pings, etc., but I
237 | am sure it will come in time.
238 |
239 | Autobahn is a great test suite. The Python server code is good, and conforms
240 | well (obviously). However for me, twisted would be a deal-breaker for writing
241 | something new. I find it a bit too complex and heavy for a simple service. If
242 | you are already using twisted though, Autobahn is probably for you.
243 |
244 | Contributing
245 | ------------
246 | We’re glad you’re interested in SocketRocket, and we’d love to see where you take it. Please read our `contributing guidelines `_ prior to submitting a Pull Request.
--------------------------------------------------------------------------------
/Pods/SocketRocket/SocketRocket/SRWebSocket.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2012 Square Inc.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | #import
18 | #import
19 |
20 | typedef NS_ENUM(NSInteger, SRReadyState) {
21 | SR_CONNECTING = 0,
22 | SR_OPEN = 1,
23 | SR_CLOSING = 2,
24 | SR_CLOSED = 3,
25 | };
26 |
27 | typedef enum SRStatusCode : NSInteger {
28 | // 0–999: Reserved and not used.
29 | SRStatusCodeNormal = 1000,
30 | SRStatusCodeGoingAway = 1001,
31 | SRStatusCodeProtocolError = 1002,
32 | SRStatusCodeUnhandledType = 1003,
33 | // 1004 reserved.
34 | SRStatusNoStatusReceived = 1005,
35 | SRStatusCodeAbnormal = 1006,
36 | SRStatusCodeInvalidUTF8 = 1007,
37 | SRStatusCodePolicyViolated = 1008,
38 | SRStatusCodeMessageTooBig = 1009,
39 | SRStatusCodeMissingExtension = 1010,
40 | SRStatusCodeInternalError = 1011,
41 | SRStatusCodeServiceRestart = 1012,
42 | SRStatusCodeTryAgainLater = 1013,
43 | // 1014: Reserved for future use by the WebSocket standard.
44 | SRStatusCodeTLSHandshake = 1015,
45 | // 1016–1999: Reserved for future use by the WebSocket standard.
46 | // 2000–2999: Reserved for use by WebSocket extensions.
47 | // 3000–3999: Available for use by libraries and frameworks. May not be used by applications. Available for registration at the IANA via first-come, first-serve.
48 | // 4000–4999: Available for use by applications.
49 | } SRStatusCode;
50 |
51 | @class SRWebSocket;
52 |
53 | extern NSString *const SRWebSocketErrorDomain;
54 | extern NSString *const SRHTTPResponseErrorKey;
55 |
56 | #pragma mark - SRWebSocketDelegate
57 |
58 | @protocol SRWebSocketDelegate;
59 |
60 | #pragma mark - SRWebSocket
61 |
62 | @interface SRWebSocket : NSObject
63 |
64 | @property (nonatomic, weak) id delegate;
65 |
66 | @property (nonatomic, readonly) SRReadyState readyState;
67 | @property (nonatomic, readonly, retain) NSURL *url;
68 |
69 |
70 | @property (nonatomic, readonly) CFHTTPMessageRef receivedHTTPHeaders;
71 |
72 | // Optional array of cookies (NSHTTPCookie objects) to apply to the connections
73 | @property (nonatomic, readwrite) NSArray * requestCookies;
74 |
75 | // This returns the negotiated protocol.
76 | // It will be nil until after the handshake completes.
77 | @property (nonatomic, readonly, copy) NSString *protocol;
78 |
79 | // Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
80 | - (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
81 | - (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
82 | - (id)initWithURLRequest:(NSURLRequest *)request;
83 |
84 | // Some helper constructors.
85 | - (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
86 | - (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
87 | - (id)initWithURL:(NSURL *)url;
88 |
89 | // Delegate queue will be dispatch_main_queue by default.
90 | // You cannot set both OperationQueue and dispatch_queue.
91 | - (void)setDelegateOperationQueue:(NSOperationQueue*) queue;
92 | - (void)setDelegateDispatchQueue:(dispatch_queue_t) queue;
93 |
94 | // By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes.
95 | - (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
96 | - (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
97 |
98 | // SRWebSockets are intended for one-time-use only. Open should be called once and only once.
99 | - (void)open;
100 |
101 | - (void)close;
102 | - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
103 |
104 | // Send a UTF8 String or Data.
105 | - (void)send:(id)data;
106 |
107 | // Send Data (can be nil) in a ping message.
108 | - (void)sendPing:(NSData *)data;
109 |
110 | @end
111 |
112 | #pragma mark - SRWebSocketDelegate
113 |
114 | @protocol SRWebSocketDelegate
115 |
116 | // message will either be an NSString if the server is using text
117 | // or NSData if the server is using binary.
118 | - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
119 |
120 | @optional
121 |
122 | - (void)webSocketDidOpen:(SRWebSocket *)webSocket;
123 | - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
124 | - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
125 | - (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;
126 |
127 | // Return YES to convert messages sent as Text to an NSString. Return NO to skip NSData -> NSString conversion for Text messages. Defaults to YES.
128 | - (BOOL)webSocketShouldConvertTextFrameToString:(SRWebSocket *)webSocket;
129 |
130 | @end
131 |
132 | #pragma mark - NSURLRequest (SRCertificateAdditions)
133 |
134 | @interface NSURLRequest (SRCertificateAdditions)
135 |
136 | @property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates;
137 |
138 | @end
139 |
140 | #pragma mark - NSMutableURLRequest (SRCertificateAdditions)
141 |
142 | @interface NSMutableURLRequest (SRCertificateAdditions)
143 |
144 | @property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates;
145 |
146 | @end
147 |
148 | #pragma mark - NSRunLoop (SRWebSocket)
149 |
150 | @interface NSRunLoop (SRWebSocket)
151 |
152 | + (NSRunLoop *)SR_networkRunLoop;
153 |
154 | @end
155 |
--------------------------------------------------------------------------------
/Pods/SocketRocket/SocketRocket/SocketRocket.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2012 Square Inc.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | #import
18 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/AFNetworking/AFNetworking-dummy.m:
--------------------------------------------------------------------------------
1 | #import
2 | @interface PodsDummy_AFNetworking : NSObject
3 | @end
4 | @implementation PodsDummy_AFNetworking
5 | @end
6 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/AFNetworking/AFNetworking-prefix.pch:
--------------------------------------------------------------------------------
1 | #ifdef __OBJC__
2 | #import
3 | #else
4 | #ifndef FOUNDATION_EXPORT
5 | #if defined(__cplusplus)
6 | #define FOUNDATION_EXPORT extern "C"
7 | #else
8 | #define FOUNDATION_EXPORT extern
9 | #endif
10 | #endif
11 | #endif
12 |
13 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/AFNetworking/AFNetworking.debug.xcconfig:
--------------------------------------------------------------------------------
1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking
2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/AFNetworking" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking"
4 | PODS_BUILD_DIR = ${BUILD_DIR}
5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
6 | PODS_ROOT = ${SRCROOT}
7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking
8 | PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking
9 | SKIP_INSTALL = YES
10 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
11 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/AFNetworking/AFNetworking.release.xcconfig:
--------------------------------------------------------------------------------
1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking
2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/AFNetworking" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking"
4 | PODS_BUILD_DIR = ${BUILD_DIR}
5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
6 | PODS_ROOT = ${SRCROOT}
7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking
8 | PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking
9 | SKIP_INSTALL = YES
10 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
11 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-MKWebSocket/Pods-MKWebSocket-acknowledgements.markdown:
--------------------------------------------------------------------------------
1 | # Acknowledgements
2 | This application makes use of the following third party libraries:
3 |
4 | ## AFNetworking
5 |
6 | Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/)
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 |
26 |
27 | ## SocketRocket
28 |
29 |
30 | Copyright 2012 Square Inc.
31 |
32 | Licensed under the Apache License, Version 2.0 (the "License");
33 | you may not use this file except in compliance with the License.
34 | You may obtain a copy of the License at
35 |
36 | http://www.apache.org/licenses/LICENSE-2.0
37 |
38 | Unless required by applicable law or agreed to in writing, software
39 | distributed under the License is distributed on an "AS IS" BASIS,
40 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41 | See the License for the specific language governing permissions and
42 | limitations under the License.
43 |
44 |
45 | Generated by CocoaPods - https://cocoapods.org
46 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-MKWebSocket/Pods-MKWebSocket-acknowledgements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreferenceSpecifiers
6 |
7 |
8 | FooterText
9 | This application makes use of the following third party libraries:
10 | Title
11 | Acknowledgements
12 | Type
13 | PSGroupSpecifier
14 |
15 |
16 | FooterText
17 | Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/)
18 |
19 | Permission is hereby granted, free of charge, to any person obtaining a copy
20 | of this software and associated documentation files (the "Software"), to deal
21 | in the Software without restriction, including without limitation the rights
22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | copies of the Software, and to permit persons to whom the Software is
24 | furnished to do so, subject to the following conditions:
25 |
26 | The above copyright notice and this permission notice shall be included in
27 | all copies or substantial portions of the Software.
28 |
29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35 | THE SOFTWARE.
36 |
37 | License
38 | MIT
39 | Title
40 | AFNetworking
41 | Type
42 | PSGroupSpecifier
43 |
44 |
45 | FooterText
46 |
47 | Copyright 2012 Square Inc.
48 |
49 | Licensed under the Apache License, Version 2.0 (the "License");
50 | you may not use this file except in compliance with the License.
51 | You may obtain a copy of the License at
52 |
53 | http://www.apache.org/licenses/LICENSE-2.0
54 |
55 | Unless required by applicable law or agreed to in writing, software
56 | distributed under the License is distributed on an "AS IS" BASIS,
57 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58 | See the License for the specific language governing permissions and
59 | limitations under the License.
60 |
61 |
62 | License
63 | Apache License, Version 2.0
64 | Title
65 | SocketRocket
66 | Type
67 | PSGroupSpecifier
68 |
69 |
70 | FooterText
71 | Generated by CocoaPods - https://cocoapods.org
72 | Title
73 |
74 | Type
75 | PSGroupSpecifier
76 |
77 |
78 | StringsTable
79 | Acknowledgements
80 | Title
81 | Acknowledgements
82 |
83 |
84 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-MKWebSocket/Pods-MKWebSocket-dummy.m:
--------------------------------------------------------------------------------
1 | #import
2 | @interface PodsDummy_Pods_MKWebSocket : NSObject
3 | @end
4 | @implementation PodsDummy_Pods_MKWebSocket
5 | @end
6 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-MKWebSocket/Pods-MKWebSocket.debug.xcconfig:
--------------------------------------------------------------------------------
1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
2 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/SocketRocket"
3 | LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" "${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket"
4 | OTHER_LDFLAGS = $(inherited) -ObjC -l"AFNetworking" -l"SocketRocket" -l"icucore" -framework "CFNetwork" -framework "Security"
5 | PODS_BUILD_DIR = ${BUILD_DIR}
6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
7 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
8 | PODS_ROOT = ${SRCROOT}/Pods
9 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
10 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-MKWebSocket/Pods-MKWebSocket.release.xcconfig:
--------------------------------------------------------------------------------
1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
2 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/SocketRocket"
3 | LIBRARY_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" "${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket"
4 | OTHER_LDFLAGS = $(inherited) -ObjC -l"AFNetworking" -l"SocketRocket" -l"icucore" -framework "CFNetwork" -framework "Security"
5 | PODS_BUILD_DIR = ${BUILD_DIR}
6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
7 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
8 | PODS_ROOT = ${SRCROOT}/Pods
9 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
10 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/SocketRocket/SocketRocket-dummy.m:
--------------------------------------------------------------------------------
1 | #import
2 | @interface PodsDummy_SocketRocket : NSObject
3 | @end
4 | @implementation PodsDummy_SocketRocket
5 | @end
6 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/SocketRocket/SocketRocket-prefix.pch:
--------------------------------------------------------------------------------
1 | #ifdef __OBJC__
2 | #import
3 | #else
4 | #ifndef FOUNDATION_EXPORT
5 | #if defined(__cplusplus)
6 | #define FOUNDATION_EXPORT extern "C"
7 | #else
8 | #define FOUNDATION_EXPORT extern
9 | #endif
10 | #endif
11 | #endif
12 |
13 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/SocketRocket/SocketRocket.debug.xcconfig:
--------------------------------------------------------------------------------
1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket
2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/SocketRocket" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/SocketRocket"
4 | PODS_BUILD_DIR = ${BUILD_DIR}
5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
6 | PODS_ROOT = ${SRCROOT}
7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/SocketRocket
8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
9 | SKIP_INSTALL = YES
10 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
11 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/SocketRocket/SocketRocket.release.xcconfig:
--------------------------------------------------------------------------------
1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket
2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/SocketRocket" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/SocketRocket"
4 | PODS_BUILD_DIR = ${BUILD_DIR}
5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
6 | PODS_ROOT = ${SRCROOT}
7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/SocketRocket
8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
9 | SKIP_INSTALL = YES
10 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MKWebSocket
2 |
3 | ## 使用SRWebSocket实现的长链接,支持cookie设置、连接异常 | 网络抖动重连、ping-pong心跳保活
4 |
5 | ### 基于SRWebSocket的WebSocket长连接:https://blog.csdn.net/z119901214/article/details/119658069
6 |
7 | ### 具体使用请参考ViewController
8 | ```objective-c
9 | - (void)viewDidLoad {
10 | [super viewDidLoad];
11 | self.view.backgroundColor = [UIColor whiteColor];
12 | // Do any additional setup after loading the view.
13 |
14 | /* 添加子模块代理 */
15 | [SOCKET_MODULE(MKTestModule) addDelegate:self];
16 |
17 | /* 添加主模块代理
18 | [[MKWebSocketClient sharedInstance] addDelegate:self];
19 | */
20 |
21 | _connectBtn.enabled = YES;
22 | _pingBtn.enabled = NO;
23 | _sendBtn.enabled = NO;
24 | _closeBtn.enabled = NO;
25 | }
26 |
27 | - (void)dealloc {
28 | /* 移除子模块代理 */
29 | [SOCKET_MODULE(MKTestModule) removeDelegate:self];
30 |
31 | /* 移除主模块代理
32 | [[MKWebSocketClient sharedInstance] removeDelegate:self];
33 | */
34 | }
35 |
36 | - (IBAction)connect:(UIButton *)sender {
37 | if (_adressTF.text.length) {
38 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_adressTF.text]];
39 | request.timeoutInterval = 25;
40 | [request setValue:@"" forHTTPHeaderField:@"Cookie"];
41 |
42 | [MKWebSocketClient sharedInstance].serverRequest = request;
43 | [[MKWebSocketClient sharedInstance] connect];
44 | }
45 | }
46 | ```
47 |
48 |
49 |
--------------------------------------------------------------------------------