├── .DS_Store ├── AFNetworking ├── AFHTTPClient.h ├── AFHTTPClient.m ├── AFHTTPRequestOperation.h ├── AFHTTPRequestOperation.m ├── AFImageRequestOperation.h ├── AFImageRequestOperation.m ├── AFJSONRequestOperation.h ├── AFJSONRequestOperation.m ├── AFNetworkActivityIndicatorManager.h ├── AFNetworkActivityIndicatorManager.m ├── AFNetworking.h ├── AFPropertyListRequestOperation.h ├── AFPropertyListRequestOperation.m ├── AFURLConnectionOperation.h ├── AFURLConnectionOperation.m ├── AFXMLRequestOperation.h ├── AFXMLRequestOperation.m ├── UIImageView+AFNetworking.h └── UIImageView+AFNetworking.m ├── FBImageGallery.pch ├── FBImageGallery.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ ├── SLAVISHM.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ ├── avish057.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── gh.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── SLAVISHM.xcuserdatad │ └── xcschemes │ │ └── xcschememanagement.plist │ ├── avish057.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── FBImageGallery.xcscheme │ │ └── xcschememanagement.plist │ └── gh.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── FBImageGallery.xcscheme │ └── xcschememanagement.plist ├── FBImageGallery ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── Image1.imageset │ │ ├── Contents.json │ │ └── Image1.png │ ├── Image2.imageset │ │ ├── Contents.json │ │ └── Image2.png │ ├── Image3.imageset │ │ ├── Contents.json │ │ └── Image3.png │ ├── Image4.imageset │ │ ├── Contents.json │ │ └── Image4.png │ ├── Image5.imageset │ │ ├── Contents.json │ │ └── Image5.png │ ├── Image6.imageset │ │ ├── Contents.json │ │ └── Image6.png │ ├── Image7.imageset │ │ ├── Contents.json │ │ └── Image7.png │ ├── cross.imageset │ │ ├── Contents.json │ │ ├── cross@1x.png │ │ ├── cross@2x.png │ │ └── cross@3x.png │ └── default_propertyImage.imageset │ │ ├── Contents.json │ │ ├── default_propertyImage.png │ │ └── default_propertyImage@2x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Constants.h ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── FBImageGalleryTests ├── FBImageGalleryTests.m └── Info.plist ├── FBImageGalleryUITests ├── FBImageGalleryUITests.m └── Info.plist ├── LICENSE ├── MHFBImageViewController ├── MHFacebookImageViewer.h ├── MHFacebookImageViewer.m ├── Resources │ ├── Done.png │ └── Done@2x.png ├── UIImageView+MHFacebookImageViewer.h └── UIImageView+MHFacebookImageViewer.m └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/.DS_Store -------------------------------------------------------------------------------- /AFNetworking/AFHTTPRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFHTTPRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFURLConnectionOperation.h" 25 | 26 | /** 27 | `AFHTTPRequestOperation` is a subclass of `AFURLConnectionOperation` for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request. 28 | */ 29 | @interface AFHTTPRequestOperation : AFURLConnectionOperation 30 | 31 | ///---------------------------------------------- 32 | /// @name Getting HTTP URL Connection Information 33 | ///---------------------------------------------- 34 | 35 | /** 36 | The last HTTP response received by the operation's connection. 37 | */ 38 | @property (readonly, nonatomic, strong) NSHTTPURLResponse *response; 39 | 40 | ///---------------------------------------------------------- 41 | /// @name Managing And Checking For Acceptable HTTP Responses 42 | ///---------------------------------------------------------- 43 | 44 | /** 45 | A Boolean value that corresponds to whether the status code of the response is within the specified set of acceptable status codes. Returns `YES` if `acceptableStatusCodes` is `nil`. 46 | */ 47 | @property (nonatomic, readonly) BOOL hasAcceptableStatusCode; 48 | 49 | /** 50 | A Boolean value that corresponds to whether the MIME type of the response is among the specified set of acceptable content types. Returns `YES` if `acceptableContentTypes` is `nil`. 51 | */ 52 | @property (nonatomic, readonly) BOOL hasAcceptableContentType; 53 | 54 | /** 55 | The callback dispatch queue on success. If `NULL` (default), the main queue is used. 56 | */ 57 | @property (nonatomic, assign) dispatch_queue_t successCallbackQueue; 58 | 59 | /** 60 | The callback dispatch queue on failure. If `NULL` (default), the main queue is used. 61 | */ 62 | @property (nonatomic, assign) dispatch_queue_t failureCallbackQueue; 63 | 64 | ///------------------------------------------------------------ 65 | /// @name Managing Acceptable HTTP Status Codes & Content Types 66 | ///------------------------------------------------------------ 67 | 68 | /** 69 | Returns an `NSIndexSet` object containing the ranges of acceptable HTTP status codes. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 70 | 71 | By default, this is the range 200 to 299, inclusive. 72 | */ 73 | + (NSIndexSet *)acceptableStatusCodes; 74 | 75 | /** 76 | Adds status codes to the set of acceptable HTTP status codes returned by `+acceptableStatusCodes` in subsequent calls by this class and its descendants. 77 | 78 | @param statusCodes The status codes to be added to the set of acceptable HTTP status codes 79 | */ 80 | + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes; 81 | 82 | /** 83 | Returns an `NSSet` object containing the acceptable MIME types. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17 84 | 85 | By default, this is `nil`. 86 | */ 87 | + (NSSet *)acceptableContentTypes; 88 | 89 | /** 90 | Adds content types to the set of acceptable MIME types returned by `+acceptableContentTypes` in subsequent calls by this class and its descendants. 91 | 92 | @param contentTypes The content types to be added to the set of acceptable MIME types 93 | */ 94 | + (void)addAcceptableContentTypes:(NSSet *)contentTypes; 95 | 96 | 97 | ///----------------------------------------------------- 98 | /// @name Determining Whether A Request Can Be Processed 99 | ///----------------------------------------------------- 100 | 101 | /** 102 | A Boolean value determining whether or not the class can process the specified request. For example, `AFJSONRequestOperation` may check to make sure the content type was `application/json` or the URL path extension was `.json`. 103 | 104 | @param urlRequest The request that is determined to be supported or not supported for this class. 105 | */ 106 | + (BOOL)canProcessRequest:(NSURLRequest *)urlRequest; 107 | 108 | ///----------------------------------------------------------- 109 | /// @name Setting Completion Block Success / Failure Callbacks 110 | ///----------------------------------------------------------- 111 | 112 | /** 113 | Sets the `completionBlock` property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If `error` returns a value, which can be caused by an unacceptable status code or content type, then `failure` is executed. Otherwise, `success` is executed. 114 | 115 | This method should be overridden in subclasses in order to specify the response object passed into the success block. 116 | 117 | @param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request. 118 | @param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request. 119 | */ 120 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 121 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; 122 | 123 | @end 124 | 125 | ///---------------- 126 | /// @name Functions 127 | ///---------------- 128 | 129 | /** 130 | Returns a set of MIME types detected in an HTTP `Accept` or `Content-Type` header. 131 | */ 132 | extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); 133 | 134 | -------------------------------------------------------------------------------- /AFNetworking/AFHTTPRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFHTTPRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFHTTPRequestOperation.h" 24 | #import 25 | 26 | // Workaround for change in imp_implementationWithBlock() with Xcode 4.5 27 | #if defined(__IPHONE_6_0) || defined(__MAC_10_8) 28 | #define AF_CAST_TO_BLOCK id 29 | #else 30 | #define AF_CAST_TO_BLOCK __bridge void * 31 | #endif 32 | 33 | #pragma clang diagnostic push 34 | #pragma clang diagnostic ignored "-Wstrict-selector-match" 35 | 36 | NSSet * AFContentTypesFromHTTPHeader(NSString *string) { 37 | if (!string) { 38 | return nil; 39 | } 40 | 41 | NSArray *mediaRanges = [string componentsSeparatedByString:@","]; 42 | NSMutableSet *mutableContentTypes = [NSMutableSet setWithCapacity:mediaRanges.count]; 43 | 44 | [mediaRanges enumerateObjectsUsingBlock:^(NSString *mediaRange, __unused NSUInteger idx, __unused BOOL *stop) { 45 | NSRange parametersRange = [mediaRange rangeOfString:@";"]; 46 | if (parametersRange.location != NSNotFound) { 47 | mediaRange = [mediaRange substringToIndex:parametersRange.location]; 48 | } 49 | 50 | mediaRange = [mediaRange stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 51 | 52 | if (mediaRange.length > 0) { 53 | [mutableContentTypes addObject:mediaRange]; 54 | } 55 | }]; 56 | 57 | return [NSSet setWithSet:mutableContentTypes]; 58 | } 59 | 60 | static void AFGetMediaTypeAndSubtypeWithString(NSString *string, NSString **type, NSString **subtype) { 61 | NSScanner *scanner = [NSScanner scannerWithString:string]; 62 | [scanner setCharactersToBeSkipped:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 63 | [scanner scanUpToString:@"/" intoString:type]; 64 | [scanner scanString:@"/" intoString:nil]; 65 | [scanner scanUpToString:@";" intoString:subtype]; 66 | } 67 | 68 | static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { 69 | NSMutableString *string = [NSMutableString string]; 70 | 71 | NSRange range = NSMakeRange([indexSet firstIndex], 1); 72 | while (range.location != NSNotFound) { 73 | NSUInteger nextIndex = [indexSet indexGreaterThanIndex:range.location]; 74 | while (nextIndex == range.location + range.length) { 75 | range.length++; 76 | nextIndex = [indexSet indexGreaterThanIndex:nextIndex]; 77 | } 78 | 79 | if (string.length) { 80 | [string appendString:@","]; 81 | } 82 | 83 | if (range.length == 1) { 84 | [string appendFormat:@"%lu", (long)range.location]; 85 | } else { 86 | NSUInteger firstIndex = range.location; 87 | NSUInteger lastIndex = firstIndex + range.length - 1; 88 | [string appendFormat:@"%lu-%lu", (long)firstIndex, (long)lastIndex]; 89 | } 90 | 91 | range.location = nextIndex; 92 | range.length = 1; 93 | } 94 | 95 | return string; 96 | } 97 | 98 | static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, id block) { 99 | Method originalMethod = class_getClassMethod(klass, selector); 100 | IMP implementation = imp_implementationWithBlock((AF_CAST_TO_BLOCK)block); 101 | class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); 102 | } 103 | 104 | #pragma mark - 105 | 106 | @interface AFHTTPRequestOperation () 107 | @property (readwrite, nonatomic, strong) NSURLRequest *request; 108 | @property (readwrite, nonatomic, strong) NSHTTPURLResponse *response; 109 | @property (readwrite, nonatomic, strong) NSError *HTTPError; 110 | @end 111 | 112 | @implementation AFHTTPRequestOperation 113 | @synthesize HTTPError = _HTTPError; 114 | @synthesize successCallbackQueue = _successCallbackQueue; 115 | @synthesize failureCallbackQueue = _failureCallbackQueue; 116 | @dynamic request; 117 | @dynamic response; 118 | 119 | - (void)dealloc { 120 | if (_successCallbackQueue) { 121 | #if !OS_OBJECT_USE_OBJC 122 | dispatch_release(_successCallbackQueue); 123 | #endif 124 | _successCallbackQueue = NULL; 125 | } 126 | 127 | if (_failureCallbackQueue) { 128 | #if !OS_OBJECT_USE_OBJC 129 | dispatch_release(_failureCallbackQueue); 130 | #endif 131 | _failureCallbackQueue = NULL; 132 | } 133 | } 134 | 135 | - (NSError *)error { 136 | if (!self.HTTPError && self.response) { 137 | if (![self hasAcceptableStatusCode] || ![self hasAcceptableContentType]) { 138 | NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; 139 | [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey]; 140 | [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; 141 | [userInfo setValue:self.request forKey:AFNetworkingOperationFailingURLRequestErrorKey]; 142 | [userInfo setValue:self.response forKey:AFNetworkingOperationFailingURLResponseErrorKey]; 143 | 144 | if (![self hasAcceptableStatusCode]) { 145 | NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; 146 | [userInfo setValue:[NSString stringWithFormat:NSLocalizedStringFromTable(@"Expected status code in (%@), got %d", @"AFNetworking", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey]; 147 | self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo]; 148 | } else if (![self hasAcceptableContentType]) { 149 | // Don't invalidate content type if there is no content 150 | if ([self.responseData length] > 0) { 151 | [userInfo setValue:[NSString stringWithFormat:NSLocalizedStringFromTable(@"Expected content type %@, got %@", @"AFNetworking", nil), [[self class] acceptableContentTypes], [self.response MIMEType]] forKey:NSLocalizedDescriptionKey]; 152 | self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo]; 153 | } 154 | } 155 | } 156 | } 157 | 158 | if (self.HTTPError) { 159 | return self.HTTPError; 160 | } else { 161 | return [super error]; 162 | } 163 | } 164 | 165 | - (NSStringEncoding)responseStringEncoding { 166 | // When no explicit charset parameter is provided by the sender, media subtypes of the "text" type are defined to have a default charset value of "ISO-8859-1" when received via HTTP. Data in character sets other than "ISO-8859-1" or its subsets MUST be labeled with an appropriate charset value. 167 | // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.4.1 168 | if (self.response && !self.response.textEncodingName && self.responseData && [self.response respondsToSelector:@selector(allHeaderFields)]) { 169 | NSString *type = nil; 170 | AFGetMediaTypeAndSubtypeWithString([[self.response allHeaderFields] valueForKey:@"Content-Type"], &type, nil); 171 | 172 | if ([type isEqualToString:@"text"]) { 173 | return NSISOLatin1StringEncoding; 174 | } 175 | } 176 | 177 | return [super responseStringEncoding]; 178 | } 179 | 180 | - (void)pause { 181 | unsigned long long offset = 0; 182 | if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) { 183 | offset = [[self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey] unsignedLongLongValue]; 184 | } else { 185 | offset = [[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length]; 186 | } 187 | 188 | NSMutableURLRequest *mutableURLRequest = [self.request mutableCopy]; 189 | if ([self.response respondsToSelector:@selector(allHeaderFields)] && [[self.response allHeaderFields] valueForKey:@"ETag"]) { 190 | [mutableURLRequest setValue:[[self.response allHeaderFields] valueForKey:@"ETag"] forHTTPHeaderField:@"If-Range"]; 191 | } 192 | [mutableURLRequest setValue:[NSString stringWithFormat:@"bytes=%llu-", offset] forHTTPHeaderField:@"Range"]; 193 | self.request = mutableURLRequest; 194 | 195 | [super pause]; 196 | } 197 | 198 | - (BOOL)hasAcceptableStatusCode { 199 | if (!self.response) { 200 | return NO; 201 | } 202 | 203 | NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; 204 | return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode]; 205 | } 206 | 207 | - (BOOL)hasAcceptableContentType { 208 | if (!self.response) { 209 | return NO; 210 | } 211 | 212 | // Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream". 213 | // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html 214 | NSString *contentType = [self.response MIMEType]; 215 | if (!contentType) { 216 | contentType = @"application/octet-stream"; 217 | } 218 | 219 | return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:contentType]; 220 | } 221 | 222 | - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue { 223 | if (successCallbackQueue != _successCallbackQueue) { 224 | if (_successCallbackQueue) { 225 | #if !OS_OBJECT_USE_OBJC 226 | dispatch_release(_successCallbackQueue); 227 | #endif 228 | _successCallbackQueue = NULL; 229 | } 230 | 231 | if (successCallbackQueue) { 232 | #if !OS_OBJECT_USE_OBJC 233 | dispatch_retain(successCallbackQueue); 234 | #endif 235 | _successCallbackQueue = successCallbackQueue; 236 | } 237 | } 238 | } 239 | 240 | - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue { 241 | if (failureCallbackQueue != _failureCallbackQueue) { 242 | if (_failureCallbackQueue) { 243 | #if !OS_OBJECT_USE_OBJC 244 | dispatch_release(_failureCallbackQueue); 245 | #endif 246 | _failureCallbackQueue = NULL; 247 | } 248 | 249 | if (failureCallbackQueue) { 250 | #if !OS_OBJECT_USE_OBJC 251 | dispatch_retain(failureCallbackQueue); 252 | #endif 253 | _failureCallbackQueue = failureCallbackQueue; 254 | } 255 | } 256 | } 257 | 258 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 259 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure 260 | { 261 | // completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle. 262 | #pragma clang diagnostic push 263 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 264 | #pragma clang diagnostic ignored "-Wgnu" 265 | self.completionBlock = ^{ 266 | if (self.error) { 267 | if (failure) { 268 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 269 | failure(self, self.error); 270 | }); 271 | } 272 | } else { 273 | if (success) { 274 | dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ 275 | success(self, self.responseData); 276 | }); 277 | } 278 | } 279 | }; 280 | #pragma clang diagnostic pop 281 | } 282 | 283 | #pragma mark - AFHTTPRequestOperation 284 | 285 | + (NSIndexSet *)acceptableStatusCodes { 286 | return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]; 287 | } 288 | 289 | + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes { 290 | NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]]; 291 | [mutableStatusCodes addIndexes:statusCodes]; 292 | AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), ^(__unused id _self) { 293 | return mutableStatusCodes; 294 | }); 295 | } 296 | 297 | + (NSSet *)acceptableContentTypes { 298 | return nil; 299 | } 300 | 301 | + (void)addAcceptableContentTypes:(NSSet *)contentTypes { 302 | NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES]; 303 | [mutableContentTypes unionSet:contentTypes]; 304 | AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), ^(__unused id _self) { 305 | return mutableContentTypes; 306 | }); 307 | } 308 | 309 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 310 | if ([[self class] isEqual:[AFHTTPRequestOperation class]]) { 311 | return YES; 312 | } 313 | 314 | return [[self acceptableContentTypes] intersectsSet:AFContentTypesFromHTTPHeader([request valueForHTTPHeaderField:@"Accept"])]; 315 | } 316 | 317 | @end 318 | 319 | #pragma clang diagnostic pop 320 | -------------------------------------------------------------------------------- /AFNetworking/AFImageRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFImageRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFHTTPRequestOperation.h" 25 | 26 | #import 27 | 28 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 29 | #import 30 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 31 | #import 32 | #endif 33 | 34 | /** 35 | `AFImageRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and processing images. 36 | 37 | ## Acceptable Content Types 38 | 39 | By default, `AFImageRequestOperation` accepts the following MIME types, which correspond to the image formats supported by UIImage or NSImage: 40 | 41 | - `image/tiff` 42 | - `image/jpeg` 43 | - `image/gif` 44 | - `image/png` 45 | - `image/ico` 46 | - `image/x-icon` 47 | - `image/bmp` 48 | - `image/x-bmp` 49 | - `image/x-xbitmap` 50 | - `image/x-win-bitmap` 51 | */ 52 | @interface AFImageRequestOperation : AFHTTPRequestOperation 53 | 54 | /** 55 | An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error. 56 | */ 57 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 58 | @property (readonly, nonatomic, strong) UIImage *responseImage; 59 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 60 | @property (readonly, nonatomic, strong) NSImage *responseImage; 61 | #endif 62 | 63 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 64 | /** 65 | The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance. 66 | */ 67 | @property (nonatomic, assign) CGFloat imageScale; 68 | #endif 69 | 70 | /** 71 | Creates and returns an `AFImageRequestOperation` object and sets the specified success callback. 72 | 73 | @param urlRequest The request object to be loaded asynchronously during execution of the operation. 74 | @param success A block object to be executed when the request finishes successfully. This block has no return value and takes a single argument, the image created from the response data of the request. 75 | 76 | @return A new image request operation 77 | */ 78 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 79 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 80 | success:(void (^)(UIImage *image))success; 81 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 82 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 83 | success:(void (^)(NSImage *image))success; 84 | #endif 85 | 86 | /** 87 | Creates and returns an `AFImageRequestOperation` object and sets the specified success callback. 88 | 89 | @param urlRequest The request object to be loaded asynchronously during execution of the operation. 90 | @param imageProcessingBlock A block object to be executed after the image request finishes successfully, but before the image is returned in the `success` block. This block takes a single argument, the image loaded from the response body, and returns the processed image. 91 | @param success A block object to be executed when the request finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). This block has no return value and takes three arguments: the request object of the operation, the response for the request, and the image created from the response data. 92 | @param failure A block object to be executed when the request finishes unsuccessfully. This block has no return value and takes three arguments: the request object of the operation, the response for the request, and the error associated with the cause for the unsuccessful operation. 93 | 94 | @return A new image request operation 95 | */ 96 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 97 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 98 | imageProcessingBlock:(UIImage *(^)(UIImage *image))imageProcessingBlock 99 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 100 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 101 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 102 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 103 | imageProcessingBlock:(NSImage *(^)(NSImage *image))imageProcessingBlock 104 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success 105 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 106 | #endif 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /AFNetworking/AFImageRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFImageRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFImageRequestOperation.h" 24 | 25 | static dispatch_queue_t image_request_operation_processing_queue() { 26 | static dispatch_queue_t af_image_request_operation_processing_queue; 27 | static dispatch_once_t onceToken; 28 | dispatch_once(&onceToken, ^{ 29 | af_image_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.image-request.processing", DISPATCH_QUEUE_CONCURRENT); 30 | }); 31 | 32 | return af_image_request_operation_processing_queue; 33 | } 34 | 35 | @interface AFImageRequestOperation () 36 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 37 | @property (readwrite, nonatomic, strong) UIImage *responseImage; 38 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 39 | @property (readwrite, nonatomic, strong) NSImage *responseImage; 40 | #endif 41 | @end 42 | 43 | @implementation AFImageRequestOperation 44 | @synthesize responseImage = _responseImage; 45 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 46 | @synthesize imageScale = _imageScale; 47 | #endif 48 | 49 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 50 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 51 | success:(void (^)(UIImage *image))success 52 | { 53 | return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, UIImage *image) { 54 | if (success) { 55 | success(image); 56 | } 57 | } failure:nil]; 58 | } 59 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 60 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 61 | success:(void (^)(NSImage *image))success 62 | { 63 | return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, NSImage *image) { 64 | if (success) { 65 | success(image); 66 | } 67 | } failure:nil]; 68 | } 69 | #endif 70 | 71 | 72 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 73 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 74 | imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock 75 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 76 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 77 | { 78 | AFImageRequestOperation *requestOperation = [(AFImageRequestOperation *)[self alloc] initWithRequest:urlRequest]; 79 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 80 | if (success) { 81 | UIImage *image = responseObject; 82 | if (imageProcessingBlock) { 83 | dispatch_async(image_request_operation_processing_queue(), ^(void) { 84 | UIImage *processedImage = imageProcessingBlock(image); 85 | #pragma clang diagnostic push 86 | #pragma clang diagnostic ignored "-Wgnu" 87 | dispatch_async(operation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { 88 | success(operation.request, operation.response, processedImage); 89 | }); 90 | #pragma clang diagnostic pop 91 | }); 92 | } else { 93 | success(operation.request, operation.response, image); 94 | } 95 | } 96 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 97 | if (failure) { 98 | failure(operation.request, operation.response, error); 99 | } 100 | }]; 101 | 102 | 103 | return requestOperation; 104 | } 105 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 106 | + (instancetype)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 107 | imageProcessingBlock:(NSImage *(^)(NSImage *))imageProcessingBlock 108 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success 109 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 110 | { 111 | AFImageRequestOperation *requestOperation = [(AFImageRequestOperation *)[self alloc] initWithRequest:urlRequest]; 112 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 113 | if (success) { 114 | NSImage *image = responseObject; 115 | if (imageProcessingBlock) { 116 | dispatch_async(image_request_operation_processing_queue(), ^(void) { 117 | NSImage *processedImage = imageProcessingBlock(image); 118 | 119 | dispatch_async(operation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { 120 | success(operation.request, operation.response, processedImage); 121 | }); 122 | }); 123 | } else { 124 | success(operation.request, operation.response, image); 125 | } 126 | } 127 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 128 | if (failure) { 129 | failure(operation.request, operation.response, error); 130 | } 131 | }]; 132 | 133 | return requestOperation; 134 | } 135 | #endif 136 | 137 | - (id)initWithRequest:(NSURLRequest *)urlRequest { 138 | self = [super initWithRequest:urlRequest]; 139 | if (!self) { 140 | return nil; 141 | } 142 | 143 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 144 | self.imageScale = [[UIScreen mainScreen] scale]; 145 | #endif 146 | 147 | return self; 148 | } 149 | 150 | 151 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 152 | - (UIImage *)responseImage { 153 | if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) { 154 | UIImage *image = [UIImage imageWithData:self.responseData]; 155 | 156 | self.responseImage = [UIImage imageWithCGImage:[image CGImage] scale:self.imageScale orientation:image.imageOrientation]; 157 | } 158 | 159 | return _responseImage; 160 | } 161 | 162 | - (void)setImageScale:(CGFloat)imageScale { 163 | #pragma clang diagnostic push 164 | #pragma clang diagnostic ignored "-Wfloat-equal" 165 | if (imageScale == _imageScale) { 166 | return; 167 | } 168 | #pragma clang diagnostic pop 169 | 170 | _imageScale = imageScale; 171 | 172 | self.responseImage = nil; 173 | } 174 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 175 | - (NSImage *)responseImage { 176 | if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) { 177 | // Ensure that the image is set to it's correct pixel width and height 178 | NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:self.responseData]; 179 | self.responseImage = [[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])]; 180 | [self.responseImage addRepresentation:bitimage]; 181 | } 182 | 183 | return _responseImage; 184 | } 185 | #endif 186 | 187 | #pragma mark - AFHTTPRequestOperation 188 | 189 | + (NSSet *)acceptableContentTypes { 190 | return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil]; 191 | } 192 | 193 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 194 | static NSSet * _acceptablePathExtension = nil; 195 | static dispatch_once_t onceToken; 196 | dispatch_once(&onceToken, ^{ 197 | _acceptablePathExtension = [[NSSet alloc] initWithObjects:@"tif", @"tiff", @"jpg", @"jpeg", @"gif", @"png", @"ico", @"bmp", @"cur", nil]; 198 | }); 199 | 200 | return [_acceptablePathExtension containsObject:[[request URL] pathExtension]] || [super canProcessRequest:request]; 201 | } 202 | 203 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 204 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure 205 | { 206 | #pragma clang diagnostic push 207 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 208 | #pragma clang diagnostic ignored "-Wgnu" 209 | 210 | self.completionBlock = ^ { 211 | dispatch_async(image_request_operation_processing_queue(), ^(void) { 212 | if (self.error) { 213 | if (failure) { 214 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 215 | failure(self, self.error); 216 | }); 217 | } 218 | } else { 219 | if (success) { 220 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 221 | UIImage *image = nil; 222 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 223 | NSImage *image = nil; 224 | #endif 225 | 226 | image = self.responseImage; 227 | 228 | dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ 229 | success(self, image); 230 | }); 231 | } 232 | } 233 | }); 234 | }; 235 | #pragma clang diagnostic pop 236 | } 237 | 238 | @end 239 | -------------------------------------------------------------------------------- /AFNetworking/AFJSONRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFJSONRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFHTTPRequestOperation.h" 25 | 26 | /** 27 | `AFJSONRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with JSON response data. 28 | 29 | ## Acceptable Content Types 30 | 31 | By default, `AFJSONRequestOperation` accepts the following MIME types, which includes the official standard, `application/json`, as well as other commonly-used types: 32 | 33 | - `application/json` 34 | - `text/json` 35 | 36 | @warning JSON parsing will use the built-in `NSJSONSerialization` class. 37 | */ 38 | @interface AFJSONRequestOperation : AFHTTPRequestOperation 39 | 40 | ///---------------------------- 41 | /// @name Getting Response Data 42 | ///---------------------------- 43 | 44 | /** 45 | A JSON object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error. 46 | */ 47 | @property (readonly, nonatomic, strong) id responseJSON; 48 | 49 | /** 50 | Options for reading the response JSON data and creating the Foundation objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONReadingOptions". 51 | */ 52 | @property (nonatomic, assign) NSJSONReadingOptions JSONReadingOptions; 53 | 54 | ///---------------------------------- 55 | /// @name Creating Request Operations 56 | ///---------------------------------- 57 | 58 | /** 59 | Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks. 60 | 61 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 62 | @param success A block object to be executed when the operation 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 JSON object created from the response data of request. 63 | @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data as JSON. 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 describing the network or parsing error that occurred. 64 | 65 | @return A new JSON request operation 66 | */ 67 | + (instancetype)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest 68 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success 69 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /AFNetworking/AFJSONRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFJSONRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFJSONRequestOperation.h" 24 | 25 | static dispatch_queue_t json_request_operation_processing_queue() { 26 | static dispatch_queue_t af_json_request_operation_processing_queue; 27 | static dispatch_once_t onceToken; 28 | dispatch_once(&onceToken, ^{ 29 | af_json_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.json-request.processing", DISPATCH_QUEUE_CONCURRENT); 30 | }); 31 | 32 | return af_json_request_operation_processing_queue; 33 | } 34 | 35 | @interface AFJSONRequestOperation () 36 | @property (readwrite, nonatomic, strong) id responseJSON; 37 | @property (readwrite, nonatomic, strong) NSError *JSONError; 38 | @property (readwrite, nonatomic, strong) NSRecursiveLock *lock; 39 | @end 40 | 41 | @implementation AFJSONRequestOperation 42 | @synthesize responseJSON = _responseJSON; 43 | @synthesize JSONReadingOptions = _JSONReadingOptions; 44 | @synthesize JSONError = _JSONError; 45 | @dynamic lock; 46 | 47 | + (instancetype)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest 48 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success 49 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure 50 | { 51 | AFJSONRequestOperation *requestOperation = [(AFJSONRequestOperation *)[self alloc] initWithRequest:urlRequest]; 52 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 53 | if (success) { 54 | success(operation.request, operation.response, responseObject); 55 | } 56 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 57 | if (failure) { 58 | failure(operation.request, operation.response, error, [(AFJSONRequestOperation *)operation responseJSON]); 59 | } 60 | }]; 61 | 62 | return requestOperation; 63 | } 64 | 65 | 66 | - (id)responseJSON { 67 | [self.lock lock]; 68 | if (!_responseJSON && [self.responseData length] > 0 && [self isFinished] && !self.JSONError) { 69 | NSError *error = nil; 70 | 71 | // Workaround for behavior of Rails to return a single space for `head :ok` (a workaround for a bug in Safari), which is not interpreted as valid input by NSJSONSerialization. 72 | // See https://github.com/rails/rails/issues/1742 73 | if (self.responseString && ![self.responseString isEqualToString:@" "]) { 74 | // Workaround for a bug in NSJSONSerialization when Unicode character escape codes are used instead of the actual character 75 | // See http://stackoverflow.com/a/12843465/157142 76 | NSData *data = [self.responseString dataUsingEncoding:NSUTF8StringEncoding]; 77 | 78 | if (data) { 79 | self.responseJSON = [NSJSONSerialization JSONObjectWithData:data options:self.JSONReadingOptions error:&error]; 80 | } else { 81 | NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; 82 | [userInfo setValue:@"Operation responseData failed decoding as a UTF-8 string" forKey:NSLocalizedDescriptionKey]; 83 | [userInfo setValue:[NSString stringWithFormat:@"Could not decode string: %@", self.responseString] forKey:NSLocalizedFailureReasonErrorKey]; 84 | error = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo]; 85 | } 86 | } 87 | 88 | self.JSONError = error; 89 | } 90 | [self.lock unlock]; 91 | 92 | return _responseJSON; 93 | } 94 | 95 | - (NSError *)error { 96 | if (_JSONError) { 97 | return _JSONError; 98 | } else { 99 | return [super error]; 100 | } 101 | } 102 | 103 | #pragma mark - AFHTTPRequestOperation 104 | 105 | + (NSSet *)acceptableContentTypes { 106 | return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; 107 | } 108 | 109 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 110 | return [[[request URL] pathExtension] isEqualToString:@"json"] || [super canProcessRequest:request]; 111 | } 112 | 113 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 114 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure 115 | { 116 | #pragma clang diagnostic push 117 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 118 | #pragma clang diagnostic ignored "-Wgnu" 119 | 120 | self.completionBlock = ^ { 121 | if (self.error) { 122 | if (failure) { 123 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 124 | failure(self, self.error); 125 | }); 126 | } 127 | } else { 128 | dispatch_async(json_request_operation_processing_queue(), ^{ 129 | id JSON = self.responseJSON; 130 | 131 | if (self.error) { 132 | if (failure) { 133 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 134 | failure(self, self.error); 135 | }); 136 | } 137 | } else { 138 | if (success) { 139 | dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ 140 | success(self, JSON); 141 | }); 142 | } 143 | } 144 | }); 145 | } 146 | }; 147 | #pragma clang diagnostic pop 148 | } 149 | 150 | @end 151 | -------------------------------------------------------------------------------- /AFNetworking/AFNetworkActivityIndicatorManager.h: -------------------------------------------------------------------------------- 1 | // AFNetworkActivityIndicatorManager.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 | 25 | #import 26 | 27 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 28 | #import 29 | 30 | /** 31 | `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a network request operation 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. 32 | 33 | 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: 34 | 35 | [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; 36 | 37 | By setting `isNetworkActivityIndicatorVisible` 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. 38 | 39 | See the Apple Human Interface Guidelines section about the Network Activity Indicator for more information: 40 | http://developer.apple.com/library/iOS/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW44 41 | */ 42 | @interface AFNetworkActivityIndicatorManager : NSObject 43 | 44 | /** 45 | A Boolean value indicating whether the manager is enabled. 46 | 47 | If YES, the manager will change status bar network activity indicator according to network operation notifications it receives. The default value is NO. 48 | */ 49 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled; 50 | 51 | /** 52 | A Boolean value indicating whether the network activity indicator is currently displayed in the status bar. 53 | */ 54 | @property (readonly, nonatomic, assign) BOOL isNetworkActivityIndicatorVisible; 55 | 56 | /** 57 | Returns the shared network activity indicator manager object for the system. 58 | 59 | @return The systemwide network activity indicator manager. 60 | */ 61 | + (instancetype)sharedManager; 62 | 63 | /** 64 | Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator. 65 | */ 66 | - (void)incrementActivityCount; 67 | 68 | /** 69 | Decrements the number of active network requests. If this number becomes zero before decrementing, this will stop animating the status bar network activity indicator. 70 | */ 71 | - (void)decrementActivityCount; 72 | 73 | @end 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /AFNetworking/AFNetworkActivityIndicatorManager.m: -------------------------------------------------------------------------------- 1 | // AFNetworkActivityIndicatorManager.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFNetworkActivityIndicatorManager.h" 24 | 25 | #import "AFHTTPRequestOperation.h" 26 | 27 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 28 | static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; 29 | 30 | @interface AFNetworkActivityIndicatorManager () 31 | @property (readwrite, nonatomic, assign) NSInteger activityCount; 32 | @property (readwrite, nonatomic, strong) NSTimer *activityIndicatorVisibilityTimer; 33 | @property (readonly, nonatomic, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; 34 | 35 | - (void)updateNetworkActivityIndicatorVisibility; 36 | - (void)updateNetworkActivityIndicatorVisibilityDelayed; 37 | @end 38 | 39 | @implementation AFNetworkActivityIndicatorManager 40 | @synthesize activityCount = _activityCount; 41 | @synthesize activityIndicatorVisibilityTimer = _activityIndicatorVisibilityTimer; 42 | @synthesize enabled = _enabled; 43 | @dynamic networkActivityIndicatorVisible; 44 | 45 | + (instancetype)sharedManager { 46 | static AFNetworkActivityIndicatorManager *_sharedManager = nil; 47 | static dispatch_once_t oncePredicate; 48 | dispatch_once(&oncePredicate, ^{ 49 | _sharedManager = [[self alloc] init]; 50 | }); 51 | 52 | return _sharedManager; 53 | } 54 | 55 | + (NSSet *)keyPathsForValuesAffectingIsNetworkActivityIndicatorVisible { 56 | return [NSSet setWithObject:@"activityCount"]; 57 | } 58 | 59 | - (id)init { 60 | self = [super init]; 61 | if (!self) { 62 | return nil; 63 | } 64 | 65 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkingOperationDidStart:) name:AFNetworkingOperationDidStartNotification object:nil]; 66 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkingOperationDidFinish:) name:AFNetworkingOperationDidFinishNotification object:nil]; 67 | 68 | return self; 69 | } 70 | 71 | - (void)dealloc { 72 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 73 | 74 | [_activityIndicatorVisibilityTimer invalidate]; 75 | 76 | } 77 | 78 | - (void)updateNetworkActivityIndicatorVisibilityDelayed { 79 | if (self.enabled) { 80 | // Delay hiding of activity indicator for a short interval, to avoid flickering 81 | if (![self isNetworkActivityIndicatorVisible]) { 82 | [self.activityIndicatorVisibilityTimer invalidate]; 83 | self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibility) userInfo:nil repeats:NO]; 84 | [[NSRunLoop mainRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes]; 85 | } else { 86 | [self performSelectorOnMainThread:@selector(updateNetworkActivityIndicatorVisibility) withObject:nil waitUntilDone:NO modes:[NSArray arrayWithObject:NSRunLoopCommonModes]]; 87 | } 88 | } 89 | } 90 | 91 | - (BOOL)isNetworkActivityIndicatorVisible { 92 | return _activityCount > 0; 93 | } 94 | 95 | - (void)updateNetworkActivityIndicatorVisibility { 96 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; 97 | } 98 | 99 | // Not exposed, but used if activityCount is set via KVC. 100 | - (NSInteger)activityCount { 101 | return _activityCount; 102 | } 103 | 104 | - (void)setActivityCount:(NSInteger)activityCount { 105 | @synchronized(self) { 106 | _activityCount = activityCount; 107 | } 108 | 109 | dispatch_async(dispatch_get_main_queue(), ^{ 110 | [self updateNetworkActivityIndicatorVisibilityDelayed]; 111 | }); 112 | } 113 | 114 | - (void)incrementActivityCount { 115 | [self willChangeValueForKey:@"activityCount"]; 116 | @synchronized(self) { 117 | _activityCount++; 118 | } 119 | [self didChangeValueForKey:@"activityCount"]; 120 | 121 | dispatch_async(dispatch_get_main_queue(), ^{ 122 | [self updateNetworkActivityIndicatorVisibilityDelayed]; 123 | }); 124 | } 125 | 126 | - (void)decrementActivityCount { 127 | [self willChangeValueForKey:@"activityCount"]; 128 | @synchronized(self) { 129 | #pragma clang diagnostic push 130 | #pragma clang diagnostic ignored "-Wgnu" 131 | _activityCount = MAX(_activityCount - 1, 0); 132 | #pragma clang diagnostic pop 133 | } 134 | [self didChangeValueForKey:@"activityCount"]; 135 | 136 | dispatch_async(dispatch_get_main_queue(), ^{ 137 | [self updateNetworkActivityIndicatorVisibilityDelayed]; 138 | }); 139 | } 140 | 141 | - (void)networkingOperationDidStart:(NSNotification *)notification { 142 | AFURLConnectionOperation *connectionOperation = [notification object]; 143 | if (connectionOperation.request.URL) { 144 | [self incrementActivityCount]; 145 | } 146 | } 147 | 148 | - (void)networkingOperationDidFinish:(NSNotification *)notification { 149 | AFURLConnectionOperation *connectionOperation = [notification object]; 150 | if (connectionOperation.request.URL) { 151 | [self decrementActivityCount]; 152 | } 153 | } 154 | 155 | @end 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /AFNetworking/AFNetworking.h: -------------------------------------------------------------------------------- 1 | // AFNetworking.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 | 26 | #ifndef _AFNETWORKING_ 27 | #define _AFNETWORKING_ 28 | 29 | #import "AFURLConnectionOperation.h" 30 | 31 | #import "AFHTTPRequestOperation.h" 32 | #import "AFJSONRequestOperation.h" 33 | #import "AFXMLRequestOperation.h" 34 | #import "AFPropertyListRequestOperation.h" 35 | #import "AFHTTPClient.h" 36 | 37 | #import "AFImageRequestOperation.h" 38 | 39 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 40 | #import "AFNetworkActivityIndicatorManager.h" 41 | #import "UIImageView+AFNetworking.h" 42 | #endif 43 | #endif /* _AFNETWORKING_ */ 44 | -------------------------------------------------------------------------------- /AFNetworking/AFPropertyListRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFPropertyListRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFHTTPRequestOperation.h" 25 | 26 | /** 27 | `AFPropertyListRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and deserializing objects with property list (plist) response data. 28 | 29 | ## Acceptable Content Types 30 | 31 | By default, `AFPropertyListRequestOperation` accepts the following MIME types: 32 | 33 | - `application/x-plist` 34 | */ 35 | @interface AFPropertyListRequestOperation : AFHTTPRequestOperation 36 | 37 | ///---------------------------- 38 | /// @name Getting Response Data 39 | ///---------------------------- 40 | 41 | /** 42 | An object deserialized from a plist constructed using the response data. 43 | */ 44 | @property (readonly, nonatomic) id responsePropertyList; 45 | 46 | ///-------------------------------------- 47 | /// @name Managing Property List Behavior 48 | ///-------------------------------------- 49 | 50 | /** 51 | One of the `NSPropertyListMutabilityOptions` options, specifying the mutability of objects deserialized from the property list. By default, this is `NSPropertyListImmutable`. 52 | */ 53 | @property (nonatomic, assign) NSPropertyListReadOptions propertyListReadOptions; 54 | 55 | /** 56 | Creates and returns an `AFPropertyListRequestOperation` object and sets the specified success and failure callbacks. 57 | 58 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 59 | @param success A block object to be executed when the operation 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 object deserialized from a plist constructed using the response data. 60 | @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while deserializing the object from a property list. 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 describing the network or parsing error that occurred. 61 | 62 | @return A new property list request operation 63 | */ 64 | + (instancetype)propertyListRequestOperationWithRequest:(NSURLRequest *)urlRequest 65 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success 66 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList))failure; 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /AFNetworking/AFPropertyListRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFPropertyListRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFPropertyListRequestOperation.h" 24 | 25 | static dispatch_queue_t property_list_request_operation_processing_queue() { 26 | static dispatch_queue_t af_property_list_request_operation_processing_queue; 27 | static dispatch_once_t onceToken; 28 | dispatch_once(&onceToken, ^{ 29 | af_property_list_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.property-list-request.processing", DISPATCH_QUEUE_CONCURRENT); 30 | }); 31 | 32 | return af_property_list_request_operation_processing_queue; 33 | } 34 | 35 | @interface AFPropertyListRequestOperation () 36 | @property (readwrite, nonatomic) id responsePropertyList; 37 | @property (readwrite, nonatomic, assign) NSPropertyListFormat propertyListFormat; 38 | @property (readwrite, nonatomic) NSError *propertyListError; 39 | @end 40 | 41 | @implementation AFPropertyListRequestOperation 42 | @synthesize responsePropertyList = _responsePropertyList; 43 | @synthesize propertyListReadOptions = _propertyListReadOptions; 44 | @synthesize propertyListFormat = _propertyListFormat; 45 | @synthesize propertyListError = _propertyListError; 46 | 47 | + (instancetype)propertyListRequestOperationWithRequest:(NSURLRequest *)request 48 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success 49 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList))failure 50 | { 51 | AFPropertyListRequestOperation *requestOperation = [(AFPropertyListRequestOperation *)[self alloc] initWithRequest:request]; 52 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 53 | if (success) { 54 | success(operation.request, operation.response, responseObject); 55 | } 56 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 57 | if (failure) { 58 | failure(operation.request, operation.response, error, [(AFPropertyListRequestOperation *)operation responsePropertyList]); 59 | } 60 | }]; 61 | 62 | return requestOperation; 63 | } 64 | 65 | - (id)initWithRequest:(NSURLRequest *)urlRequest { 66 | self = [super initWithRequest:urlRequest]; 67 | if (!self) { 68 | return nil; 69 | } 70 | 71 | self.propertyListReadOptions = NSPropertyListImmutable; 72 | 73 | return self; 74 | } 75 | 76 | 77 | - (id)responsePropertyList { 78 | if (!_responsePropertyList && [self.responseData length] > 0 && [self isFinished]) { 79 | NSPropertyListFormat format; 80 | NSError *error = nil; 81 | self.responsePropertyList = [NSPropertyListSerialization propertyListWithData:self.responseData options:self.propertyListReadOptions format:&format error:&error]; 82 | self.propertyListFormat = format; 83 | self.propertyListError = error; 84 | } 85 | 86 | return _responsePropertyList; 87 | } 88 | 89 | - (NSError *)error { 90 | if (_propertyListError) { 91 | return _propertyListError; 92 | } else { 93 | return [super error]; 94 | } 95 | } 96 | 97 | #pragma mark - AFHTTPRequestOperation 98 | 99 | + (NSSet *)acceptableContentTypes { 100 | return [NSSet setWithObjects:@"application/x-plist", nil]; 101 | } 102 | 103 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 104 | return [[[request URL] pathExtension] isEqualToString:@"plist"] || [super canProcessRequest:request]; 105 | } 106 | 107 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 108 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure 109 | { 110 | #pragma clang diagnostic push 111 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 112 | #pragma clang diagnostic ignored "-Wgnu" 113 | self.completionBlock = ^ { 114 | if (self.error) { 115 | if (failure) { 116 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 117 | failure(self, self.error); 118 | }); 119 | } 120 | } else { 121 | dispatch_async(property_list_request_operation_processing_queue(), ^(void) { 122 | id propertyList = self.responsePropertyList; 123 | 124 | if (self.propertyListError) { 125 | if (failure) { 126 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 127 | failure(self, self.error); 128 | }); 129 | } 130 | } else { 131 | if (success) { 132 | dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ 133 | success(self, propertyList); 134 | }); 135 | } 136 | } 137 | }); 138 | } 139 | }; 140 | #pragma clang diagnostic pop 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /AFNetworking/AFURLConnectionOperation.h: -------------------------------------------------------------------------------- 1 | // AFURLConnectionOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 | 25 | #import 26 | 27 | /** 28 | `AFURLConnectionOperation` is a subclass of `NSOperation` that implements `NSURLConnection` delegate methods. 29 | 30 | ## Subclassing Notes 31 | 32 | This is the base class of all network request operations. You may wish to create your own subclass in order to implement additional `NSURLConnection` delegate methods (see "`NSURLConnection` Delegate Methods" below), or to provide additional properties and/or class constructors. 33 | 34 | If you are creating a subclass that communicates over the HTTP or HTTPS protocols, you may want to consider subclassing `AFHTTPRequestOperation` instead, as it supports specifying acceptable content types or status codes. 35 | 36 | ## NSURLConnection Delegate Methods 37 | 38 | `AFURLConnectionOperation` implements the following `NSURLConnection` delegate methods: 39 | 40 | - `connection:didReceiveResponse:` 41 | - `connection:didReceiveData:` 42 | - `connectionDidFinishLoading:` 43 | - `connection:didFailWithError:` 44 | - `connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:` 45 | - `connection:willCacheResponse:` 46 | - `connectionShouldUseCredentialStorage:` 47 | - `connection:needNewBodyStream:` 48 | 49 | When _AFNETWORKING_PIN_SSL_CERTIFICATES_ is defined, the following authentication delegate method is implemented: 50 | 51 | - `connection:willSendRequestForAuthenticationChallenge:` 52 | 53 | Otherwise, the following authentication delegate methods are implemented: 54 | 55 | - `connection:canAuthenticateAgainstProtectionSpace:` 56 | - `connection:didReceiveAuthenticationChallenge:` 57 | 58 | If any of these methods are overridden in a subclass, they _must_ call the `super` implementation first. 59 | 60 | ## Class Constructors 61 | 62 | Class constructors, or methods that return an unowned instance, are the preferred way for subclasses to encapsulate any particular logic for handling the setup or parsing of response data. For instance, `AFJSONRequestOperation` provides `JSONRequestOperationWithRequest:success:failure:`, which takes block arguments, whose parameter on for a successful request is the JSON object initialized from the `response data`. 63 | 64 | ## Callbacks and Completion Blocks 65 | 66 | The built-in `completionBlock` provided by `NSOperation` allows for custom behavior to be executed after the request finishes. It is a common pattern for class constructors in subclasses to take callback block parameters, and execute them conditionally in the body of its `completionBlock`. Make sure to handle cancelled operations appropriately when setting a `completionBlock` (i.e. returning early before parsing response data). See the implementation of any of the `AFHTTPRequestOperation` subclasses for an example of this. 67 | 68 | Subclasses are strongly discouraged from overriding `setCompletionBlock:`, as `AFURLConnectionOperation`'s implementation includes a workaround to mitigate retain cycles, and what Apple rather ominously refers to as ["The Deallocation Problem"](http://developer.apple.com/library/ios/#technotes/tn2109/). 69 | 70 | ## SSL Pinning 71 | 72 | Relying on the CA trust model to validate SSL certificates exposes your app to security vulnerabilities, such as man-in-the-middle attacks. For applications that connect to known servers, SSL certificate pinning provides an increased level of security, by checking server certificate validity against those specified in the app bundle. 73 | 74 | SSL with certificate pinning is strongly recommended for any application that transmits sensitive information to an external webservice. 75 | 76 | When `_AFNETWORKING_PIN_SSL_CERTIFICATES_` is defined and the Security framework is linked, connections will be validated on all matching certificates with a `.cer` extension in the bundle root. 77 | 78 | ## NSCoding & NSCopying Conformance 79 | 80 | `AFURLConnectionOperation` conforms to the `NSCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. However, because of the intrinsic limitations of capturing the exact state of an operation at a particular moment, there are some important caveats to keep in mind: 81 | 82 | ### NSCoding Caveats 83 | 84 | - Encoded operations do not include any block or stream properties. Be sure to set `completionBlock`, `outputStream`, and any callback blocks as necessary when using `-initWithCoder:` or `NSKeyedUnarchiver`. 85 | - Operations are paused on `encodeWithCoder:`. If the operation was encoded while paused or still executing, its archived state will return `YES` for `isReady`. Otherwise, the state of an operation when encoding will remain unchanged. 86 | 87 | ### NSCopying Caveats 88 | 89 | - `-copy` and `-copyWithZone:` return a new operation with the `NSURLRequest` of the original. So rather than an exact copy of the operation at that particular instant, the copying mechanism returns a completely new instance, which can be useful for retrying operations. 90 | - A copy of an operation will not include the `outputStream` of the original. 91 | - Operation copies do not include `completionBlock`. `completionBlock` often strongly captures a reference to `self`, which would otherwise have the unintuitive side-effect of pointing to the _original_ operation when copied. 92 | */ 93 | 94 | #ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_ 95 | typedef enum { 96 | AFSSLPinningModeNone, 97 | AFSSLPinningModePublicKey, 98 | AFSSLPinningModeCertificate, 99 | } AFURLConnectionOperationSSLPinningMode; 100 | #endif 101 | 102 | @interface AFURLConnectionOperation : NSOperation = 50000) || \ 104 | (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080) 105 | NSURLConnectionDataDelegate, 106 | #endif 107 | NSCoding, NSCopying> 108 | 109 | ///------------------------------- 110 | /// @name Accessing Run Loop Modes 111 | ///------------------------------- 112 | 113 | /** 114 | The run loop modes in which the operation will run on the network thread. By default, this is a single-member set containing `NSRunLoopCommonModes`. 115 | */ 116 | @property (nonatomic, strong) NSSet *runLoopModes; 117 | 118 | ///----------------------------------------- 119 | /// @name Getting URL Connection Information 120 | ///----------------------------------------- 121 | 122 | /** 123 | The request used by the operation's connection. 124 | */ 125 | @property (readonly, nonatomic, strong) NSURLRequest *request; 126 | 127 | /** 128 | The last response received by the operation's connection. 129 | */ 130 | @property (readonly, nonatomic, strong) NSURLResponse *response; 131 | 132 | /** 133 | The error, if any, that occurred in the lifecycle of the request. 134 | */ 135 | @property (readonly, nonatomic, strong) NSError *error; 136 | 137 | /** 138 | Whether the connection should accept an invalid SSL certificate. 139 | 140 | If `_AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_` is set, this property defaults to `YES` for backwards compatibility. Otherwise, this property defaults to `NO`. 141 | */ 142 | @property (nonatomic, assign) BOOL allowsInvalidSSLCertificate; 143 | 144 | ///---------------------------- 145 | /// @name Getting Response Data 146 | ///---------------------------- 147 | 148 | /** 149 | The data received during the request. 150 | */ 151 | @property (readonly, nonatomic, strong) NSData *responseData; 152 | 153 | /** 154 | The string representation of the response data. 155 | */ 156 | @property (readonly, nonatomic, copy) NSString *responseString; 157 | 158 | /** 159 | The string encoding of the response. 160 | 161 | If the response does not specify a valid string encoding, `responseStringEncoding` will return `NSUTF8StringEncoding`. 162 | */ 163 | @property (readonly, nonatomic, assign) NSStringEncoding responseStringEncoding; 164 | 165 | ///------------------------------- 166 | /// @name Managing URL Credentials 167 | ///------------------------------- 168 | 169 | /** 170 | Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default. 171 | 172 | This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`. 173 | */ 174 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage; 175 | 176 | /** 177 | The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. 178 | 179 | This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. 180 | */ 181 | @property (nonatomic, strong) NSURLCredential *credential; 182 | 183 | /** 184 | The pinning mode which will be used for SSL connections. `AFSSLPinningModePublicKey` by default. 185 | 186 | To enable SSL Pinning, `#define _AFNETWORKING_PIN_SSL_CERTIFICATES_` in `Prefix.pch`. Also, make sure that the Security framework is linked with the binary. See the "SSL Pinning" section in the `AFURLConnectionOperation`" header for more information. 187 | */ 188 | #ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_ 189 | @property (nonatomic, assign) AFURLConnectionOperationSSLPinningMode SSLPinningMode; 190 | #endif 191 | 192 | ///------------------------ 193 | /// @name Accessing Streams 194 | ///------------------------ 195 | 196 | /** 197 | The input stream used to read data to be sent during the request. 198 | 199 | This property acts as a proxy to the `HTTPBodyStream` property of `request`. 200 | */ 201 | @property (nonatomic, strong) NSInputStream *inputStream; 202 | 203 | /** 204 | The output stream that is used to write data received until the request is finished. 205 | 206 | By default, data is accumulated into a buffer that is stored into `responseData` upon completion of the request. When `outputStream` is set, the data will not be accumulated into an internal buffer, and as a result, the `responseData` property of the completed request will be `nil`. The output stream will be scheduled in the network thread runloop upon being set. 207 | */ 208 | @property (nonatomic, strong) NSOutputStream *outputStream; 209 | 210 | ///--------------------------------------------- 211 | /// @name Managing Request Operation Information 212 | ///--------------------------------------------- 213 | 214 | /** 215 | The user info dictionary for the receiver. 216 | */ 217 | @property (nonatomic, strong) NSDictionary *userInfo; 218 | 219 | ///------------------------------------------------------ 220 | /// @name Initializing an AFURLConnectionOperation Object 221 | ///------------------------------------------------------ 222 | 223 | /** 224 | Initializes and returns a newly allocated operation object with a url connection configured with the specified url request. 225 | 226 | This is the designated initializer. 227 | 228 | @param urlRequest The request object to be used by the operation connection. 229 | */ 230 | - (id)initWithRequest:(NSURLRequest *)urlRequest; 231 | 232 | ///---------------------------------- 233 | /// @name Pausing / Resuming Requests 234 | ///---------------------------------- 235 | 236 | /** 237 | Pauses the execution of the request operation. 238 | 239 | A paused operation returns `NO` for `-isReady`, `-isExecuting`, and `-isFinished`. As such, it will remain in an `NSOperationQueue` until it is either cancelled or resumed. Pausing a finished, cancelled, or paused operation has no effect. 240 | */ 241 | - (void)pause; 242 | 243 | /** 244 | Whether the request operation is currently paused. 245 | 246 | @return `YES` if the operation is currently paused, otherwise `NO`. 247 | */ 248 | - (BOOL)isPaused; 249 | 250 | /** 251 | Resumes the execution of the paused request operation. 252 | 253 | Pause/Resume behavior varies depending on the underlying implementation for the operation class. In its base implementation, resuming a paused requests restarts the original request. However, since HTTP defines a specification for how to request a specific content range, `AFHTTPRequestOperation` will resume downloading the request from where it left off, instead of restarting the original request. 254 | */ 255 | - (void)resume; 256 | 257 | ///---------------------------------------------- 258 | /// @name Configuring Backgrounding Task Behavior 259 | ///---------------------------------------------- 260 | 261 | /** 262 | Specifies that the operation should continue execution after the app has entered the background, and the expiration handler for that background task. 263 | 264 | @param handler A handler to be called shortly before the application’s remaining background time reaches 0. The handler is wrapped in a block that cancels the operation, and cleans up and marks the end of execution, unlike the `handler` parameter in `UIApplication -beginBackgroundTaskWithExpirationHandler:`, which expects this to be done in the handler itself. The handler is called synchronously on the main thread, thus blocking the application’s suspension momentarily while the application is notified. 265 | */ 266 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 267 | - (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler; 268 | #endif 269 | 270 | ///--------------------------------- 271 | /// @name Setting Progress Callbacks 272 | ///--------------------------------- 273 | 274 | /** 275 | Sets a callback to be called when an undetermined number of bytes have been uploaded to the server. 276 | 277 | @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes three arguments: the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread. 278 | */ 279 | - (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block; 280 | 281 | /** 282 | Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. 283 | 284 | @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the `NSHTTPURLResponse` object. This block may be called multiple times, and will execute on the main thread. 285 | */ 286 | - (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block; 287 | 288 | ///------------------------------------------------- 289 | /// @name Setting NSURLConnection Delegate Callbacks 290 | ///------------------------------------------------- 291 | 292 | #ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_ 293 | /** 294 | Sets a block to be executed when the connection will authenticate a challenge in order to download its request, as handled by the `NSURLConnectionDelegate` method `connection:willSendRequestForAuthenticationChallenge:`. 295 | 296 | @param block A block object to be executed when the connection will authenticate a challenge in order to download its request. The block has no return type and takes two arguments: the URL connection object, and the challenge that must be authenticated. This block must invoke one of the challenge-responder methods (NSURLAuthenticationChallengeSender protocol). 297 | 298 | If `allowsInvalidSSLCertificate` is set to YES, `connection:willSendRequestForAuthenticationChallenge:` will attempt to have the challenge sender use credentials with invalid SSL certificates. 299 | */ 300 | - (void)setWillSendRequestForAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))block; 301 | 302 | #else 303 | 304 | /** 305 | Sets a block to be executed to determine whether the connection should be able to respond to a protection space's form of authentication, as handled by the `NSURLConnectionDelegate` method `connection:canAuthenticateAgainstProtectionSpace:`. 306 | 307 | If `allowsInvalidSSLCertificate` is set to YES, `connection:canAuthenticateAgainstProtectionSpace:` will accept invalid SSL certificates, returning `YES` if the protection space authentication method is `NSURLAuthenticationMethodServerTrust`. 308 | 309 | @param block A block object to be executed to determine whether the connection should be able to respond to a protection space's form of authentication. The block has a `BOOL` return type and takes two arguments: the URL connection object, and the protection space to authenticate against. 310 | */ 311 | - (void)setAuthenticationAgainstProtectionSpaceBlock:(BOOL (^)(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace))block; 312 | 313 | /** 314 | Sets a block to be executed when the connection must authenticate a challenge in order to download its request, as handled by the `NSURLConnectionDelegate` method `connection:didReceiveAuthenticationChallenge:`. 315 | 316 | @param block A block object to be executed when the connection must authenticate a challenge in order to download its request. The block has no return type and takes two arguments: the URL connection object, and the challenge that must be authenticated. 317 | 318 | If `allowsInvalidSSLCertificate` is set to YES, `connection:didReceiveAuthenticationChallenge:` will attempt to have the challenge sender use credentials with invalid SSL certificates. 319 | */ 320 | - (void)setAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))block; 321 | 322 | #endif 323 | 324 | /** 325 | Sets a block to be executed when the server redirects the request from one URL to another URL, or when the request URL changed by the `NSURLProtocol` subclass handling the request in order to standardize its format, as handled by the `NSURLConnectionDelegate` method `connection:willSendRequest:redirectResponse:`. 326 | 327 | @param block A block object to be executed when the request URL was changed. The block returns an `NSURLRequest` object, the URL request to redirect, and takes three arguments: the URL connection object, the the proposed redirected request, and the URL response that caused the redirect. 328 | */ 329 | - (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block; 330 | 331 | 332 | /** 333 | Sets a block to be executed to modify the response a connection will cache, if any, as handled by the `NSURLConnectionDelegate` method `connection:willCacheResponse:`. 334 | 335 | @param block A block object to be executed to determine what response a connection will cache, if any. The block returns an `NSCachedURLResponse` object, the cached response to store in memory or `nil` to prevent the response from being cached, and takes two arguments: the URL connection object, and the cached response provided for the request. 336 | */ 337 | - (void)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block; 338 | 339 | @end 340 | 341 | ///---------------- 342 | /// @name Constants 343 | ///---------------- 344 | 345 | /** 346 | ## SSL Pinning Options 347 | 348 | The following constants are provided by `AFURLConnectionOperation` as possible SSL Pinning options. 349 | 350 | enum { 351 | AFSSLPinningModeNone, 352 | AFSSLPinningModePublicKey, 353 | AFSSLPinningModeCertificate, 354 | } 355 | 356 | `AFSSLPinningModeNone` 357 | Do not pin SSL connections 358 | 359 | `AFSSLPinningModePublicKey` 360 | Pin SSL connections to certificate public key (SPKI). 361 | 362 | `AFSSLPinningModeCertificate` 363 | Pin SSL connections to exact certificate. This may cause problems when your certificate expires and needs re-issuance. 364 | 365 | ## User info dictionary keys 366 | 367 | These keys may exist in the user info dictionary, in addition to those defined for NSError. 368 | 369 | - `NSString * const AFNetworkingOperationFailingURLRequestErrorKey` 370 | - `NSString * const AFNetworkingOperationFailingURLResponseErrorKey` 371 | 372 | ### Constants 373 | 374 | `AFNetworkingOperationFailingURLRequestErrorKey` 375 | The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. 376 | 377 | `AFNetworkingOperationFailingURLResponseErrorKey` 378 | The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. 379 | 380 | ## Error Domains 381 | 382 | The following error domain is predefined. 383 | 384 | - `NSString * const AFNetworkingErrorDomain` 385 | 386 | ### Constants 387 | 388 | `AFNetworkingErrorDomain` 389 | AFNetworking errors. Error codes for `AFNetworkingErrorDomain` correspond to codes in `NSURLErrorDomain`. 390 | */ 391 | extern NSString * const AFNetworkingErrorDomain; 392 | extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey; 393 | extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey; 394 | 395 | ///-------------------- 396 | /// @name Notifications 397 | ///-------------------- 398 | 399 | /** 400 | Posted when an operation begins executing. 401 | */ 402 | extern NSString * const AFNetworkingOperationDidStartNotification; 403 | 404 | /** 405 | Posted when an operation finishes. 406 | */ 407 | extern NSString * const AFNetworkingOperationDidFinishNotification; 408 | -------------------------------------------------------------------------------- /AFNetworking/AFXMLRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFXMLRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFHTTPRequestOperation.h" 25 | 26 | #import 27 | 28 | /** 29 | `AFXMLRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with XML response data. 30 | 31 | ## Acceptable Content Types 32 | 33 | By default, `AFXMLRequestOperation` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types: 34 | 35 | - `application/xml` 36 | - `text/xml` 37 | 38 | ## Use With AFHTTPClient 39 | 40 | When `AFXMLRequestOperation` is registered with `AFHTTPClient`, the response object in the success callback of `HTTPRequestOperationWithRequest:success:failure:` will be an instance of `NSXMLParser`. On platforms that support `NSXMLDocument`, you have the option to ignore the response object, and simply use the `responseXMLDocument` property of the operation argument of the callback. 41 | */ 42 | @interface AFXMLRequestOperation : AFHTTPRequestOperation 43 | 44 | ///---------------------------- 45 | /// @name Getting Response Data 46 | ///---------------------------- 47 | 48 | /** 49 | An `NSXMLParser` object constructed from the response data. 50 | */ 51 | @property (readonly, nonatomic, strong) NSXMLParser *responseXMLParser; 52 | 53 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 54 | /** 55 | An `NSXMLDocument` object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error. 56 | */ 57 | @property (readonly, nonatomic, strong) NSXMLDocument *responseXMLDocument; 58 | #endif 59 | 60 | /** 61 | Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks. 62 | 63 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 64 | @param success A block object to be executed when the operation 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 XML parser constructed with the response data of request. 65 | @param failure A block object to be executed when the operation finishes unsuccessfully. 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 describing the network error that occurred. 66 | 67 | @return A new XML request operation 68 | */ 69 | + (instancetype)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest 70 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success 71 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure; 72 | 73 | 74 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 75 | /** 76 | Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks. 77 | 78 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 79 | @param success A block object to be executed when the operation 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 XML document created from the response data of request. 80 | @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data as XML. 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 describing the network or parsing error that occurred. 81 | 82 | @return A new XML request operation 83 | */ 84 | + (instancetype)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest 85 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success 86 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure; 87 | #endif 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /AFNetworking/AFXMLRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFXMLRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFXMLRequestOperation.h" 24 | 25 | #include 26 | 27 | static dispatch_queue_t xml_request_operation_processing_queue() { 28 | static dispatch_queue_t af_xml_request_operation_processing_queue; 29 | static dispatch_once_t onceToken; 30 | dispatch_once(&onceToken, ^{ 31 | af_xml_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.xml-request.processing", DISPATCH_QUEUE_CONCURRENT); 32 | }); 33 | 34 | return af_xml_request_operation_processing_queue; 35 | } 36 | 37 | @interface AFXMLRequestOperation () 38 | @property (readwrite, nonatomic, strong) NSXMLParser *responseXMLParser; 39 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 40 | @property (readwrite, nonatomic, strong) NSXMLDocument *responseXMLDocument; 41 | #endif 42 | @property (readwrite, nonatomic, strong) NSError *XMLError; 43 | @end 44 | 45 | @implementation AFXMLRequestOperation 46 | @synthesize responseXMLParser = _responseXMLParser; 47 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 48 | @synthesize responseXMLDocument = _responseXMLDocument; 49 | #endif 50 | @synthesize XMLError = _XMLError; 51 | 52 | + (instancetype)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest 53 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success 54 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure 55 | { 56 | AFXMLRequestOperation *requestOperation = [(AFXMLRequestOperation *)[self alloc] initWithRequest:urlRequest]; 57 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 58 | if (success) { 59 | success(operation.request, operation.response, responseObject); 60 | } 61 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 62 | if (failure) { 63 | failure(operation.request, operation.response, error, [(AFXMLRequestOperation *)operation responseXMLParser]); 64 | } 65 | }]; 66 | 67 | return requestOperation; 68 | } 69 | 70 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 71 | + (instancetype)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest 72 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success 73 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure 74 | { 75 | AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest]; 76 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, __unused id responseObject) { 77 | if (success) { 78 | NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument]; 79 | success(operation.request, operation.response, XMLDocument); 80 | } 81 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 82 | if (failure) { 83 | NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument]; 84 | failure(operation.request, operation.response, error, XMLDocument); 85 | } 86 | }]; 87 | 88 | return requestOperation; 89 | } 90 | #endif 91 | 92 | 93 | - (NSXMLParser *)responseXMLParser { 94 | if (!_responseXMLParser && [self.responseData length] > 0 && [self isFinished]) { 95 | self.responseXMLParser = [[NSXMLParser alloc] initWithData:self.responseData]; 96 | } 97 | 98 | return _responseXMLParser; 99 | } 100 | 101 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED 102 | - (NSXMLDocument *)responseXMLDocument { 103 | if (!_responseXMLDocument && [self.responseData length] > 0 && [self isFinished]) { 104 | NSError *error = nil; 105 | self.responseXMLDocument = [[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error]; 106 | self.XMLError = error; 107 | } 108 | 109 | return _responseXMLDocument; 110 | } 111 | #endif 112 | 113 | - (NSError *)error { 114 | if (_XMLError) { 115 | return _XMLError; 116 | } else { 117 | return [super error]; 118 | } 119 | } 120 | 121 | #pragma mark - NSOperation 122 | 123 | - (void)cancel { 124 | [super cancel]; 125 | 126 | self.responseXMLParser.delegate = nil; 127 | } 128 | 129 | #pragma mark - AFHTTPRequestOperation 130 | 131 | + (NSSet *)acceptableContentTypes { 132 | return [NSSet setWithObjects:@"application/xml", @"text/xml", nil]; 133 | } 134 | 135 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 136 | return [[[request URL] pathExtension] isEqualToString:@"xml"] || [super canProcessRequest:request]; 137 | } 138 | 139 | - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 140 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure 141 | { 142 | #pragma clang diagnostic push 143 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 144 | #pragma clang diagnostic ignored "-Wgnu" 145 | self.completionBlock = ^ { 146 | dispatch_async(xml_request_operation_processing_queue(), ^(void) { 147 | NSXMLParser *XMLParser = self.responseXMLParser; 148 | 149 | if (self.error) { 150 | if (failure) { 151 | dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ 152 | failure(self, self.error); 153 | }); 154 | } 155 | } else { 156 | if (success) { 157 | dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ 158 | success(self, XMLParser); 159 | }); 160 | } 161 | } 162 | }); 163 | }; 164 | #pragma clang diagnostic pop 165 | } 166 | 167 | @end 168 | -------------------------------------------------------------------------------- /AFNetworking/UIImageView+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIImageView+AFNetworking.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 "AFImageRequestOperation.h" 25 | 26 | #import 27 | 28 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 29 | #import 30 | 31 | /** 32 | 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. 33 | */ 34 | @interface UIImageView (AFNetworking) 35 | 36 | /** 37 | Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL, and sets it the request is finished. Any previous image request for the receiver will be cancelled. 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. 38 | 39 | By default, URL requests have 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:` 40 | 41 | @param url The URL used for the image request. 42 | */ 43 | - (void)setImageWithURL:(NSURL *)url; 44 | 45 | /** 46 | Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL. Any previous image request for the receiver will be cancelled. 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. 47 | 48 | By default, URL requests have 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:` 49 | 50 | @param url The URL used for the image request. 51 | @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. 52 | */ 53 | - (void)setImageWithURL:(NSURL *)url 54 | placeholderImage:(UIImage *)placeholderImage; 55 | 56 | /** 57 | Creates and enqueues an image request operation, which asynchronously downloads the image with the specified URL request object. Any previous image request for the receiver will be cancelled. 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. 58 | 59 | 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 executed. 60 | 61 | @param urlRequest The URL request used for the image request. 62 | @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. 63 | @param success A block to be executed when the image request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). 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 request and response parameters will be `nil`. 64 | @param failure A block object to be executed when the image request operation 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. 65 | */ 66 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 67 | placeholderImage:(UIImage *)placeholderImage 68 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 69 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 70 | 71 | /** 72 | Cancels any executing image request operation for the receiver, if one exists. 73 | */ 74 | - (void)cancelImageRequestOperation; 75 | 76 | @end 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /AFNetworking/UIImageView+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // UIImageView+AFNetworking.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.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 | 26 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 27 | #import "UIImageView+AFNetworking.h" 28 | 29 | @interface AFImageCache : NSCache 30 | - (UIImage *)cachedImageForRequest:(NSURLRequest *)request; 31 | - (void)cacheImage:(UIImage *)image 32 | forRequest:(NSURLRequest *)request; 33 | @end 34 | 35 | #pragma mark - 36 | 37 | static char kAFImageRequestOperationObjectKey; 38 | 39 | @interface UIImageView (_AFNetworking) 40 | @property (readwrite, nonatomic, strong, setter = af_setImageRequestOperation:) AFImageRequestOperation *af_imageRequestOperation; 41 | @end 42 | 43 | @implementation UIImageView (_AFNetworking) 44 | @dynamic af_imageRequestOperation; 45 | @end 46 | 47 | #pragma mark - 48 | 49 | @implementation UIImageView (AFNetworking) 50 | 51 | - (AFHTTPRequestOperation *)af_imageRequestOperation { 52 | return (AFHTTPRequestOperation *)objc_getAssociatedObject(self, &kAFImageRequestOperationObjectKey); 53 | } 54 | 55 | - (void)af_setImageRequestOperation:(AFImageRequestOperation *)imageRequestOperation { 56 | objc_setAssociatedObject(self, &kAFImageRequestOperationObjectKey, imageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 57 | } 58 | 59 | + (NSOperationQueue *)af_sharedImageRequestOperationQueue { 60 | static NSOperationQueue *_af_imageRequestOperationQueue = nil; 61 | static dispatch_once_t onceToken; 62 | dispatch_once(&onceToken, ^{ 63 | _af_imageRequestOperationQueue = [[NSOperationQueue alloc] init]; 64 | [_af_imageRequestOperationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount]; 65 | }); 66 | 67 | return _af_imageRequestOperationQueue; 68 | } 69 | 70 | + (AFImageCache *)af_sharedImageCache { 71 | static AFImageCache *_af_imageCache = nil; 72 | static dispatch_once_t oncePredicate; 73 | dispatch_once(&oncePredicate, ^{ 74 | _af_imageCache = [[AFImageCache alloc] init]; 75 | }); 76 | 77 | return _af_imageCache; 78 | } 79 | 80 | #pragma mark - 81 | 82 | - (void)setImageWithURL:(NSURL *)url { 83 | [self setImageWithURL:url placeholderImage:nil]; 84 | } 85 | 86 | - (void)setImageWithURL:(NSURL *)url 87 | placeholderImage:(UIImage *)placeholderImage 88 | { 89 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 90 | [request addValue:@"image/*" forHTTPHeaderField:@"Accept"]; 91 | 92 | [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil]; 93 | } 94 | 95 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 96 | placeholderImage:(UIImage *)placeholderImage 97 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 98 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 99 | { 100 | [self cancelImageRequestOperation]; 101 | 102 | UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest]; 103 | if (cachedImage) { 104 | if (success) { 105 | success(nil, nil, cachedImage); 106 | } else { 107 | self.image = cachedImage; 108 | } 109 | 110 | self.af_imageRequestOperation = nil; 111 | } else { 112 | self.image = placeholderImage; 113 | 114 | AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; 115 | [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 116 | if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) { 117 | if (success) { 118 | success(operation.request, operation.response, responseObject); 119 | } else if (responseObject) { 120 | self.image = responseObject; 121 | } 122 | 123 | if (self.af_imageRequestOperation == operation) { 124 | self.af_imageRequestOperation = nil; 125 | } 126 | } 127 | 128 | [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest]; 129 | } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 130 | if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) { 131 | if (failure) { 132 | failure(operation.request, operation.response, error); 133 | } 134 | 135 | if (self.af_imageRequestOperation == operation) { 136 | self.af_imageRequestOperation = nil; 137 | } 138 | } 139 | }]; 140 | 141 | self.af_imageRequestOperation = requestOperation; 142 | 143 | [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation]; 144 | } 145 | } 146 | 147 | - (void)cancelImageRequestOperation { 148 | [self.af_imageRequestOperation cancel]; 149 | self.af_imageRequestOperation = nil; 150 | } 151 | 152 | @end 153 | 154 | #pragma mark - 155 | 156 | static inline NSString * AFImageCacheKeyFromURLRequest(NSURLRequest *request) { 157 | return [[request URL] absoluteString]; 158 | } 159 | 160 | @implementation AFImageCache 161 | 162 | - (UIImage *)cachedImageForRequest:(NSURLRequest *)request { 163 | switch ([request cachePolicy]) { 164 | case NSURLRequestReloadIgnoringCacheData: 165 | case NSURLRequestReloadIgnoringLocalAndRemoteCacheData: 166 | return nil; 167 | default: 168 | break; 169 | } 170 | 171 | return [self objectForKey:AFImageCacheKeyFromURLRequest(request)]; 172 | } 173 | 174 | - (void)cacheImage:(UIImage *)image 175 | forRequest:(NSURLRequest *)request 176 | { 177 | if (image && request) { 178 | [self setObject:image forKey:AFImageCacheKeyFromURLRequest(request)]; 179 | } 180 | } 181 | 182 | @end 183 | 184 | #endif 185 | -------------------------------------------------------------------------------- /FBImageGallery.pch: -------------------------------------------------------------------------------- 1 | // 2 | // FBImageGallery.pch 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #ifndef FBImageGallery_pch 10 | #define FBImageGallery_pch 11 | 12 | #import "AppDelegate.h" 13 | #import "Constants.h" 14 | 15 | 16 | // Include any system framework and library headers here that should be included in all compilation units. 17 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. 18 | 19 | #endif /* FBImageGallery_pch */ 20 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E68D656C1E9F7CF900F66A28 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D656B1E9F7CF900F66A28 /* main.m */; }; 11 | E68D656F1E9F7CF900F66A28 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D656E1E9F7CF900F66A28 /* AppDelegate.m */; }; 12 | E68D65721E9F7CF900F66A28 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65711E9F7CF900F66A28 /* ViewController.m */; }; 13 | E68D65751E9F7CF900F66A28 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E68D65731E9F7CF900F66A28 /* Main.storyboard */; }; 14 | E68D65771E9F7CF900F66A28 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E68D65761E9F7CF900F66A28 /* Assets.xcassets */; }; 15 | E68D657A1E9F7CF900F66A28 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E68D65781E9F7CF900F66A28 /* LaunchScreen.storyboard */; }; 16 | E68D65851E9F7CF900F66A28 /* FBImageGalleryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65841E9F7CF900F66A28 /* FBImageGalleryTests.m */; }; 17 | E68D65901E9F7CF900F66A28 /* FBImageGalleryUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D658F1E9F7CF900F66A28 /* FBImageGalleryUITests.m */; }; 18 | E68D65A51E9F7D6900F66A28 /* MHFacebookImageViewer.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D659F1E9F7D6900F66A28 /* MHFacebookImageViewer.m */; }; 19 | E68D65A61E9F7D6900F66A28 /* Done.png in Resources */ = {isa = PBXBuildFile; fileRef = E68D65A11E9F7D6900F66A28 /* Done.png */; }; 20 | E68D65A71E9F7D6900F66A28 /* Done@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E68D65A21E9F7D6900F66A28 /* Done@2x.png */; }; 21 | E68D65A81E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65A41E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.m */; }; 22 | E68D65BD1E9F9E2600F66A28 /* AFHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65AB1E9F9E2600F66A28 /* AFHTTPClient.m */; }; 23 | E68D65BE1E9F9E2600F66A28 /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65AD1E9F9E2600F66A28 /* AFHTTPRequestOperation.m */; }; 24 | E68D65BF1E9F9E2600F66A28 /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65AF1E9F9E2600F66A28 /* AFImageRequestOperation.m */; }; 25 | E68D65C01E9F9E2600F66A28 /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65B11E9F9E2600F66A28 /* AFJSONRequestOperation.m */; }; 26 | E68D65C11E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65B31E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.m */; }; 27 | E68D65C21E9F9E2600F66A28 /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65B61E9F9E2600F66A28 /* AFPropertyListRequestOperation.m */; }; 28 | E68D65C31E9F9E2600F66A28 /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65B81E9F9E2600F66A28 /* AFURLConnectionOperation.m */; }; 29 | E68D65C41E9F9E2600F66A28 /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65BA1E9F9E2600F66A28 /* AFXMLRequestOperation.m */; }; 30 | E68D65C51E9F9E2600F66A28 /* UIImageView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = E68D65BC1E9F9E2600F66A28 /* UIImageView+AFNetworking.m */; }; 31 | /* End PBXBuildFile section */ 32 | 33 | /* Begin PBXContainerItemProxy section */ 34 | E68D65811E9F7CF900F66A28 /* PBXContainerItemProxy */ = { 35 | isa = PBXContainerItemProxy; 36 | containerPortal = E68D655F1E9F7CF900F66A28 /* Project object */; 37 | proxyType = 1; 38 | remoteGlobalIDString = E68D65661E9F7CF900F66A28; 39 | remoteInfo = FBImageGallery; 40 | }; 41 | E68D658C1E9F7CF900F66A28 /* PBXContainerItemProxy */ = { 42 | isa = PBXContainerItemProxy; 43 | containerPortal = E68D655F1E9F7CF900F66A28 /* Project object */; 44 | proxyType = 1; 45 | remoteGlobalIDString = E68D65661E9F7CF900F66A28; 46 | remoteInfo = FBImageGallery; 47 | }; 48 | /* End PBXContainerItemProxy section */ 49 | 50 | /* Begin PBXFileReference section */ 51 | E68D65671E9F7CF900F66A28 /* FBImageGallery.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FBImageGallery.app; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | E68D656B1E9F7CF900F66A28 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 53 | E68D656D1E9F7CF900F66A28 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 54 | E68D656E1E9F7CF900F66A28 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 55 | E68D65701E9F7CF900F66A28 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 56 | E68D65711E9F7CF900F66A28 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 57 | E68D65741E9F7CF900F66A28 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 58 | E68D65761E9F7CF900F66A28 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 59 | E68D65791E9F7CF900F66A28 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 60 | E68D657B1E9F7CF900F66A28 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 61 | E68D65801E9F7CF900F66A28 /* FBImageGalleryTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FBImageGalleryTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 62 | E68D65841E9F7CF900F66A28 /* FBImageGalleryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBImageGalleryTests.m; sourceTree = ""; }; 63 | E68D65861E9F7CF900F66A28 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 64 | E68D658B1E9F7CF900F66A28 /* FBImageGalleryUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FBImageGalleryUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 65 | E68D658F1E9F7CF900F66A28 /* FBImageGalleryUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBImageGalleryUITests.m; sourceTree = ""; }; 66 | E68D65911E9F7CF900F66A28 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 67 | E68D659E1E9F7D6900F66A28 /* MHFacebookImageViewer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MHFacebookImageViewer.h; sourceTree = ""; }; 68 | E68D659F1E9F7D6900F66A28 /* MHFacebookImageViewer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHFacebookImageViewer.m; sourceTree = ""; }; 69 | E68D65A11E9F7D6900F66A28 /* Done.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Done.png; sourceTree = ""; }; 70 | E68D65A21E9F7D6900F66A28 /* Done@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Done@2x.png"; sourceTree = ""; }; 71 | E68D65A31E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+MHFacebookImageViewer.h"; sourceTree = ""; }; 72 | E68D65A41E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+MHFacebookImageViewer.m"; sourceTree = ""; }; 73 | E68D65AA1E9F9E2500F66A28 /* AFHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFHTTPClient.h; sourceTree = ""; }; 74 | E68D65AB1E9F9E2600F66A28 /* AFHTTPClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPClient.m; sourceTree = ""; }; 75 | E68D65AC1E9F9E2600F66A28 /* AFHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFHTTPRequestOperation.h; sourceTree = ""; }; 76 | E68D65AD1E9F9E2600F66A28 /* AFHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPRequestOperation.m; sourceTree = ""; }; 77 | E68D65AE1E9F9E2600F66A28 /* AFImageRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFImageRequestOperation.h; sourceTree = ""; }; 78 | E68D65AF1E9F9E2600F66A28 /* AFImageRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFImageRequestOperation.m; sourceTree = ""; }; 79 | E68D65B01E9F9E2600F66A28 /* AFJSONRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFJSONRequestOperation.h; sourceTree = ""; }; 80 | E68D65B11E9F9E2600F66A28 /* AFJSONRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFJSONRequestOperation.m; sourceTree = ""; }; 81 | E68D65B21E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFNetworkActivityIndicatorManager.h; sourceTree = ""; }; 82 | E68D65B31E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFNetworkActivityIndicatorManager.m; sourceTree = ""; }; 83 | E68D65B41E9F9E2600F66A28 /* AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFNetworking.h; sourceTree = ""; }; 84 | E68D65B51E9F9E2600F66A28 /* AFPropertyListRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFPropertyListRequestOperation.h; sourceTree = ""; }; 85 | E68D65B61E9F9E2600F66A28 /* AFPropertyListRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFPropertyListRequestOperation.m; sourceTree = ""; }; 86 | E68D65B71E9F9E2600F66A28 /* AFURLConnectionOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFURLConnectionOperation.h; sourceTree = ""; }; 87 | E68D65B81E9F9E2600F66A28 /* AFURLConnectionOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFURLConnectionOperation.m; sourceTree = ""; }; 88 | E68D65B91E9F9E2600F66A28 /* AFXMLRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFXMLRequestOperation.h; sourceTree = ""; }; 89 | E68D65BA1E9F9E2600F66A28 /* AFXMLRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFXMLRequestOperation.m; sourceTree = ""; }; 90 | E68D65BB1E9F9E2600F66A28 /* UIImageView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+AFNetworking.h"; sourceTree = ""; }; 91 | E68D65BC1E9F9E2600F66A28 /* UIImageView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+AFNetworking.m"; sourceTree = ""; }; 92 | E68D65C61E9F9F6B00F66A28 /* Constants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = ""; }; 93 | E68D65C71E9F9FEC00F66A28 /* FBImageGallery.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBImageGallery.pch; sourceTree = ""; }; 94 | /* End PBXFileReference section */ 95 | 96 | /* Begin PBXFrameworksBuildPhase section */ 97 | E68D65641E9F7CF900F66A28 /* Frameworks */ = { 98 | isa = PBXFrameworksBuildPhase; 99 | buildActionMask = 2147483647; 100 | files = ( 101 | ); 102 | runOnlyForDeploymentPostprocessing = 0; 103 | }; 104 | E68D657D1E9F7CF900F66A28 /* Frameworks */ = { 105 | isa = PBXFrameworksBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | ); 109 | runOnlyForDeploymentPostprocessing = 0; 110 | }; 111 | E68D65881E9F7CF900F66A28 /* Frameworks */ = { 112 | isa = PBXFrameworksBuildPhase; 113 | buildActionMask = 2147483647; 114 | files = ( 115 | ); 116 | runOnlyForDeploymentPostprocessing = 0; 117 | }; 118 | /* End PBXFrameworksBuildPhase section */ 119 | 120 | /* Begin PBXGroup section */ 121 | E68D655E1E9F7CF900F66A28 = { 122 | isa = PBXGroup; 123 | children = ( 124 | E68D65C71E9F9FEC00F66A28 /* FBImageGallery.pch */, 125 | E68D65A91E9F9E2500F66A28 /* AFNetworking */, 126 | E68D659D1E9F7D6900F66A28 /* MHFBImageViewController */, 127 | E68D65691E9F7CF900F66A28 /* FBImageGallery */, 128 | E68D65831E9F7CF900F66A28 /* FBImageGalleryTests */, 129 | E68D658E1E9F7CF900F66A28 /* FBImageGalleryUITests */, 130 | E68D65681E9F7CF900F66A28 /* Products */, 131 | ); 132 | sourceTree = ""; 133 | }; 134 | E68D65681E9F7CF900F66A28 /* Products */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | E68D65671E9F7CF900F66A28 /* FBImageGallery.app */, 138 | E68D65801E9F7CF900F66A28 /* FBImageGalleryTests.xctest */, 139 | E68D658B1E9F7CF900F66A28 /* FBImageGalleryUITests.xctest */, 140 | ); 141 | name = Products; 142 | sourceTree = ""; 143 | }; 144 | E68D65691E9F7CF900F66A28 /* FBImageGallery */ = { 145 | isa = PBXGroup; 146 | children = ( 147 | E68D656D1E9F7CF900F66A28 /* AppDelegate.h */, 148 | E68D656E1E9F7CF900F66A28 /* AppDelegate.m */, 149 | E68D65701E9F7CF900F66A28 /* ViewController.h */, 150 | E68D65711E9F7CF900F66A28 /* ViewController.m */, 151 | E68D65731E9F7CF900F66A28 /* Main.storyboard */, 152 | E68D65761E9F7CF900F66A28 /* Assets.xcassets */, 153 | E68D65781E9F7CF900F66A28 /* LaunchScreen.storyboard */, 154 | E68D657B1E9F7CF900F66A28 /* Info.plist */, 155 | E68D656A1E9F7CF900F66A28 /* Supporting Files */, 156 | E68D65C61E9F9F6B00F66A28 /* Constants.h */, 157 | ); 158 | path = FBImageGallery; 159 | sourceTree = ""; 160 | }; 161 | E68D656A1E9F7CF900F66A28 /* Supporting Files */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | E68D656B1E9F7CF900F66A28 /* main.m */, 165 | ); 166 | name = "Supporting Files"; 167 | sourceTree = ""; 168 | }; 169 | E68D65831E9F7CF900F66A28 /* FBImageGalleryTests */ = { 170 | isa = PBXGroup; 171 | children = ( 172 | E68D65841E9F7CF900F66A28 /* FBImageGalleryTests.m */, 173 | E68D65861E9F7CF900F66A28 /* Info.plist */, 174 | ); 175 | path = FBImageGalleryTests; 176 | sourceTree = ""; 177 | }; 178 | E68D658E1E9F7CF900F66A28 /* FBImageGalleryUITests */ = { 179 | isa = PBXGroup; 180 | children = ( 181 | E68D658F1E9F7CF900F66A28 /* FBImageGalleryUITests.m */, 182 | E68D65911E9F7CF900F66A28 /* Info.plist */, 183 | ); 184 | path = FBImageGalleryUITests; 185 | sourceTree = ""; 186 | }; 187 | E68D659D1E9F7D6900F66A28 /* MHFBImageViewController */ = { 188 | isa = PBXGroup; 189 | children = ( 190 | E68D659E1E9F7D6900F66A28 /* MHFacebookImageViewer.h */, 191 | E68D659F1E9F7D6900F66A28 /* MHFacebookImageViewer.m */, 192 | E68D65A01E9F7D6900F66A28 /* Resources */, 193 | E68D65A31E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.h */, 194 | E68D65A41E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.m */, 195 | ); 196 | path = MHFBImageViewController; 197 | sourceTree = ""; 198 | }; 199 | E68D65A01E9F7D6900F66A28 /* Resources */ = { 200 | isa = PBXGroup; 201 | children = ( 202 | E68D65A11E9F7D6900F66A28 /* Done.png */, 203 | E68D65A21E9F7D6900F66A28 /* Done@2x.png */, 204 | ); 205 | path = Resources; 206 | sourceTree = ""; 207 | }; 208 | E68D65A91E9F9E2500F66A28 /* AFNetworking */ = { 209 | isa = PBXGroup; 210 | children = ( 211 | E68D65AA1E9F9E2500F66A28 /* AFHTTPClient.h */, 212 | E68D65AB1E9F9E2600F66A28 /* AFHTTPClient.m */, 213 | E68D65AC1E9F9E2600F66A28 /* AFHTTPRequestOperation.h */, 214 | E68D65AD1E9F9E2600F66A28 /* AFHTTPRequestOperation.m */, 215 | E68D65AE1E9F9E2600F66A28 /* AFImageRequestOperation.h */, 216 | E68D65AF1E9F9E2600F66A28 /* AFImageRequestOperation.m */, 217 | E68D65B01E9F9E2600F66A28 /* AFJSONRequestOperation.h */, 218 | E68D65B11E9F9E2600F66A28 /* AFJSONRequestOperation.m */, 219 | E68D65B21E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.h */, 220 | E68D65B31E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.m */, 221 | E68D65B41E9F9E2600F66A28 /* AFNetworking.h */, 222 | E68D65B51E9F9E2600F66A28 /* AFPropertyListRequestOperation.h */, 223 | E68D65B61E9F9E2600F66A28 /* AFPropertyListRequestOperation.m */, 224 | E68D65B71E9F9E2600F66A28 /* AFURLConnectionOperation.h */, 225 | E68D65B81E9F9E2600F66A28 /* AFURLConnectionOperation.m */, 226 | E68D65B91E9F9E2600F66A28 /* AFXMLRequestOperation.h */, 227 | E68D65BA1E9F9E2600F66A28 /* AFXMLRequestOperation.m */, 228 | E68D65BB1E9F9E2600F66A28 /* UIImageView+AFNetworking.h */, 229 | E68D65BC1E9F9E2600F66A28 /* UIImageView+AFNetworking.m */, 230 | ); 231 | path = AFNetworking; 232 | sourceTree = ""; 233 | }; 234 | /* End PBXGroup section */ 235 | 236 | /* Begin PBXNativeTarget section */ 237 | E68D65661E9F7CF900F66A28 /* FBImageGallery */ = { 238 | isa = PBXNativeTarget; 239 | buildConfigurationList = E68D65941E9F7CF900F66A28 /* Build configuration list for PBXNativeTarget "FBImageGallery" */; 240 | buildPhases = ( 241 | E68D65631E9F7CF900F66A28 /* Sources */, 242 | E68D65641E9F7CF900F66A28 /* Frameworks */, 243 | E68D65651E9F7CF900F66A28 /* Resources */, 244 | ); 245 | buildRules = ( 246 | ); 247 | dependencies = ( 248 | ); 249 | name = FBImageGallery; 250 | productName = FBImageGallery; 251 | productReference = E68D65671E9F7CF900F66A28 /* FBImageGallery.app */; 252 | productType = "com.apple.product-type.application"; 253 | }; 254 | E68D657F1E9F7CF900F66A28 /* FBImageGalleryTests */ = { 255 | isa = PBXNativeTarget; 256 | buildConfigurationList = E68D65971E9F7CF900F66A28 /* Build configuration list for PBXNativeTarget "FBImageGalleryTests" */; 257 | buildPhases = ( 258 | E68D657C1E9F7CF900F66A28 /* Sources */, 259 | E68D657D1E9F7CF900F66A28 /* Frameworks */, 260 | E68D657E1E9F7CF900F66A28 /* Resources */, 261 | ); 262 | buildRules = ( 263 | ); 264 | dependencies = ( 265 | E68D65821E9F7CF900F66A28 /* PBXTargetDependency */, 266 | ); 267 | name = FBImageGalleryTests; 268 | productName = FBImageGalleryTests; 269 | productReference = E68D65801E9F7CF900F66A28 /* FBImageGalleryTests.xctest */; 270 | productType = "com.apple.product-type.bundle.unit-test"; 271 | }; 272 | E68D658A1E9F7CF900F66A28 /* FBImageGalleryUITests */ = { 273 | isa = PBXNativeTarget; 274 | buildConfigurationList = E68D659A1E9F7CF900F66A28 /* Build configuration list for PBXNativeTarget "FBImageGalleryUITests" */; 275 | buildPhases = ( 276 | E68D65871E9F7CF900F66A28 /* Sources */, 277 | E68D65881E9F7CF900F66A28 /* Frameworks */, 278 | E68D65891E9F7CF900F66A28 /* Resources */, 279 | ); 280 | buildRules = ( 281 | ); 282 | dependencies = ( 283 | E68D658D1E9F7CF900F66A28 /* PBXTargetDependency */, 284 | ); 285 | name = FBImageGalleryUITests; 286 | productName = FBImageGalleryUITests; 287 | productReference = E68D658B1E9F7CF900F66A28 /* FBImageGalleryUITests.xctest */; 288 | productType = "com.apple.product-type.bundle.ui-testing"; 289 | }; 290 | /* End PBXNativeTarget section */ 291 | 292 | /* Begin PBXProject section */ 293 | E68D655F1E9F7CF900F66A28 /* Project object */ = { 294 | isa = PBXProject; 295 | attributes = { 296 | LastUpgradeCheck = 0830; 297 | ORGANIZATIONNAME = Slack; 298 | TargetAttributes = { 299 | E68D65661E9F7CF900F66A28 = { 300 | CreatedOnToolsVersion = 8.3; 301 | DevelopmentTeam = 4NPK7439NE; 302 | ProvisioningStyle = Automatic; 303 | }; 304 | E68D657F1E9F7CF900F66A28 = { 305 | CreatedOnToolsVersion = 8.3; 306 | ProvisioningStyle = Automatic; 307 | TestTargetID = E68D65661E9F7CF900F66A28; 308 | }; 309 | E68D658A1E9F7CF900F66A28 = { 310 | CreatedOnToolsVersion = 8.3; 311 | ProvisioningStyle = Automatic; 312 | TestTargetID = E68D65661E9F7CF900F66A28; 313 | }; 314 | }; 315 | }; 316 | buildConfigurationList = E68D65621E9F7CF900F66A28 /* Build configuration list for PBXProject "FBImageGallery" */; 317 | compatibilityVersion = "Xcode 3.2"; 318 | developmentRegion = English; 319 | hasScannedForEncodings = 0; 320 | knownRegions = ( 321 | en, 322 | Base, 323 | ); 324 | mainGroup = E68D655E1E9F7CF900F66A28; 325 | productRefGroup = E68D65681E9F7CF900F66A28 /* Products */; 326 | projectDirPath = ""; 327 | projectRoot = ""; 328 | targets = ( 329 | E68D65661E9F7CF900F66A28 /* FBImageGallery */, 330 | E68D657F1E9F7CF900F66A28 /* FBImageGalleryTests */, 331 | E68D658A1E9F7CF900F66A28 /* FBImageGalleryUITests */, 332 | ); 333 | }; 334 | /* End PBXProject section */ 335 | 336 | /* Begin PBXResourcesBuildPhase section */ 337 | E68D65651E9F7CF900F66A28 /* Resources */ = { 338 | isa = PBXResourcesBuildPhase; 339 | buildActionMask = 2147483647; 340 | files = ( 341 | E68D657A1E9F7CF900F66A28 /* LaunchScreen.storyboard in Resources */, 342 | E68D65A61E9F7D6900F66A28 /* Done.png in Resources */, 343 | E68D65771E9F7CF900F66A28 /* Assets.xcassets in Resources */, 344 | E68D65A71E9F7D6900F66A28 /* Done@2x.png in Resources */, 345 | E68D65751E9F7CF900F66A28 /* Main.storyboard in Resources */, 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | }; 349 | E68D657E1E9F7CF900F66A28 /* Resources */ = { 350 | isa = PBXResourcesBuildPhase; 351 | buildActionMask = 2147483647; 352 | files = ( 353 | ); 354 | runOnlyForDeploymentPostprocessing = 0; 355 | }; 356 | E68D65891E9F7CF900F66A28 /* Resources */ = { 357 | isa = PBXResourcesBuildPhase; 358 | buildActionMask = 2147483647; 359 | files = ( 360 | ); 361 | runOnlyForDeploymentPostprocessing = 0; 362 | }; 363 | /* End PBXResourcesBuildPhase section */ 364 | 365 | /* Begin PBXSourcesBuildPhase section */ 366 | E68D65631E9F7CF900F66A28 /* Sources */ = { 367 | isa = PBXSourcesBuildPhase; 368 | buildActionMask = 2147483647; 369 | files = ( 370 | E68D65BF1E9F9E2600F66A28 /* AFImageRequestOperation.m in Sources */, 371 | E68D65721E9F7CF900F66A28 /* ViewController.m in Sources */, 372 | E68D656F1E9F7CF900F66A28 /* AppDelegate.m in Sources */, 373 | E68D65C41E9F9E2600F66A28 /* AFXMLRequestOperation.m in Sources */, 374 | E68D65A51E9F7D6900F66A28 /* MHFacebookImageViewer.m in Sources */, 375 | E68D65C51E9F9E2600F66A28 /* UIImageView+AFNetworking.m in Sources */, 376 | E68D65C31E9F9E2600F66A28 /* AFURLConnectionOperation.m in Sources */, 377 | E68D65C11E9F9E2600F66A28 /* AFNetworkActivityIndicatorManager.m in Sources */, 378 | E68D656C1E9F7CF900F66A28 /* main.m in Sources */, 379 | E68D65C01E9F9E2600F66A28 /* AFJSONRequestOperation.m in Sources */, 380 | E68D65A81E9F7D6900F66A28 /* UIImageView+MHFacebookImageViewer.m in Sources */, 381 | E68D65C21E9F9E2600F66A28 /* AFPropertyListRequestOperation.m in Sources */, 382 | E68D65BD1E9F9E2600F66A28 /* AFHTTPClient.m in Sources */, 383 | E68D65BE1E9F9E2600F66A28 /* AFHTTPRequestOperation.m in Sources */, 384 | ); 385 | runOnlyForDeploymentPostprocessing = 0; 386 | }; 387 | E68D657C1E9F7CF900F66A28 /* Sources */ = { 388 | isa = PBXSourcesBuildPhase; 389 | buildActionMask = 2147483647; 390 | files = ( 391 | E68D65851E9F7CF900F66A28 /* FBImageGalleryTests.m in Sources */, 392 | ); 393 | runOnlyForDeploymentPostprocessing = 0; 394 | }; 395 | E68D65871E9F7CF900F66A28 /* Sources */ = { 396 | isa = PBXSourcesBuildPhase; 397 | buildActionMask = 2147483647; 398 | files = ( 399 | E68D65901E9F7CF900F66A28 /* FBImageGalleryUITests.m in Sources */, 400 | ); 401 | runOnlyForDeploymentPostprocessing = 0; 402 | }; 403 | /* End PBXSourcesBuildPhase section */ 404 | 405 | /* Begin PBXTargetDependency section */ 406 | E68D65821E9F7CF900F66A28 /* PBXTargetDependency */ = { 407 | isa = PBXTargetDependency; 408 | target = E68D65661E9F7CF900F66A28 /* FBImageGallery */; 409 | targetProxy = E68D65811E9F7CF900F66A28 /* PBXContainerItemProxy */; 410 | }; 411 | E68D658D1E9F7CF900F66A28 /* PBXTargetDependency */ = { 412 | isa = PBXTargetDependency; 413 | target = E68D65661E9F7CF900F66A28 /* FBImageGallery */; 414 | targetProxy = E68D658C1E9F7CF900F66A28 /* PBXContainerItemProxy */; 415 | }; 416 | /* End PBXTargetDependency section */ 417 | 418 | /* Begin PBXVariantGroup section */ 419 | E68D65731E9F7CF900F66A28 /* Main.storyboard */ = { 420 | isa = PBXVariantGroup; 421 | children = ( 422 | E68D65741E9F7CF900F66A28 /* Base */, 423 | ); 424 | name = Main.storyboard; 425 | sourceTree = ""; 426 | }; 427 | E68D65781E9F7CF900F66A28 /* LaunchScreen.storyboard */ = { 428 | isa = PBXVariantGroup; 429 | children = ( 430 | E68D65791E9F7CF900F66A28 /* Base */, 431 | ); 432 | name = LaunchScreen.storyboard; 433 | sourceTree = ""; 434 | }; 435 | /* End PBXVariantGroup section */ 436 | 437 | /* Begin XCBuildConfiguration section */ 438 | E68D65921E9F7CF900F66A28 /* Debug */ = { 439 | isa = XCBuildConfiguration; 440 | buildSettings = { 441 | ALWAYS_SEARCH_USER_PATHS = NO; 442 | CLANG_ANALYZER_NONNULL = YES; 443 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 444 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 445 | CLANG_CXX_LIBRARY = "libc++"; 446 | CLANG_ENABLE_MODULES = YES; 447 | CLANG_ENABLE_OBJC_ARC = YES; 448 | CLANG_WARN_BOOL_CONVERSION = YES; 449 | CLANG_WARN_CONSTANT_CONVERSION = YES; 450 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 451 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 452 | CLANG_WARN_EMPTY_BODY = YES; 453 | CLANG_WARN_ENUM_CONVERSION = YES; 454 | CLANG_WARN_INFINITE_RECURSION = YES; 455 | CLANG_WARN_INT_CONVERSION = YES; 456 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 457 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 458 | CLANG_WARN_UNREACHABLE_CODE = YES; 459 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 460 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 461 | COPY_PHASE_STRIP = NO; 462 | DEBUG_INFORMATION_FORMAT = dwarf; 463 | ENABLE_STRICT_OBJC_MSGSEND = YES; 464 | ENABLE_TESTABILITY = YES; 465 | GCC_C_LANGUAGE_STANDARD = gnu99; 466 | GCC_DYNAMIC_NO_PIC = NO; 467 | GCC_NO_COMMON_BLOCKS = YES; 468 | GCC_OPTIMIZATION_LEVEL = 0; 469 | GCC_PREPROCESSOR_DEFINITIONS = ( 470 | "DEBUG=1", 471 | "$(inherited)", 472 | ); 473 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 474 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 475 | GCC_WARN_UNDECLARED_SELECTOR = YES; 476 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 477 | GCC_WARN_UNUSED_FUNCTION = YES; 478 | GCC_WARN_UNUSED_VARIABLE = YES; 479 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 480 | MTL_ENABLE_DEBUG_INFO = YES; 481 | ONLY_ACTIVE_ARCH = YES; 482 | SDKROOT = iphoneos; 483 | TARGETED_DEVICE_FAMILY = "1,2"; 484 | }; 485 | name = Debug; 486 | }; 487 | E68D65931E9F7CF900F66A28 /* Release */ = { 488 | isa = XCBuildConfiguration; 489 | buildSettings = { 490 | ALWAYS_SEARCH_USER_PATHS = NO; 491 | CLANG_ANALYZER_NONNULL = YES; 492 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 493 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 494 | CLANG_CXX_LIBRARY = "libc++"; 495 | CLANG_ENABLE_MODULES = YES; 496 | CLANG_ENABLE_OBJC_ARC = YES; 497 | CLANG_WARN_BOOL_CONVERSION = YES; 498 | CLANG_WARN_CONSTANT_CONVERSION = YES; 499 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 500 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 501 | CLANG_WARN_EMPTY_BODY = YES; 502 | CLANG_WARN_ENUM_CONVERSION = YES; 503 | CLANG_WARN_INFINITE_RECURSION = YES; 504 | CLANG_WARN_INT_CONVERSION = YES; 505 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 506 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 507 | CLANG_WARN_UNREACHABLE_CODE = YES; 508 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 509 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 510 | COPY_PHASE_STRIP = NO; 511 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 512 | ENABLE_NS_ASSERTIONS = NO; 513 | ENABLE_STRICT_OBJC_MSGSEND = YES; 514 | GCC_C_LANGUAGE_STANDARD = gnu99; 515 | GCC_NO_COMMON_BLOCKS = YES; 516 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 517 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 518 | GCC_WARN_UNDECLARED_SELECTOR = YES; 519 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 520 | GCC_WARN_UNUSED_FUNCTION = YES; 521 | GCC_WARN_UNUSED_VARIABLE = YES; 522 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 523 | MTL_ENABLE_DEBUG_INFO = NO; 524 | SDKROOT = iphoneos; 525 | TARGETED_DEVICE_FAMILY = "1,2"; 526 | VALIDATE_PRODUCT = YES; 527 | }; 528 | name = Release; 529 | }; 530 | E68D65951E9F7CF900F66A28 /* Debug */ = { 531 | isa = XCBuildConfiguration; 532 | buildSettings = { 533 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 534 | DEVELOPMENT_TEAM = 4NPK7439NE; 535 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 536 | GCC_PREFIX_HEADER = "$(SRCROOT)/FBImageGallery.pch"; 537 | INFOPLIST_FILE = FBImageGallery/Info.plist; 538 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 539 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 540 | PRODUCT_BUNDLE_IDENTIFIER = com.slack.com.FBImageGallery; 541 | PRODUCT_NAME = "$(TARGET_NAME)"; 542 | }; 543 | name = Debug; 544 | }; 545 | E68D65961E9F7CF900F66A28 /* Release */ = { 546 | isa = XCBuildConfiguration; 547 | buildSettings = { 548 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 549 | DEVELOPMENT_TEAM = 4NPK7439NE; 550 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 551 | GCC_PREFIX_HEADER = "$(SRCROOT)/FBImageGallery.pch"; 552 | INFOPLIST_FILE = FBImageGallery/Info.plist; 553 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 554 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 555 | PRODUCT_BUNDLE_IDENTIFIER = com.slack.com.FBImageGallery; 556 | PRODUCT_NAME = "$(TARGET_NAME)"; 557 | }; 558 | name = Release; 559 | }; 560 | E68D65981E9F7CF900F66A28 /* Debug */ = { 561 | isa = XCBuildConfiguration; 562 | buildSettings = { 563 | BUNDLE_LOADER = "$(TEST_HOST)"; 564 | INFOPLIST_FILE = FBImageGalleryTests/Info.plist; 565 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 566 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 567 | PRODUCT_BUNDLE_IDENTIFIER = com.slack.com.FBImageGalleryTests; 568 | PRODUCT_NAME = "$(TARGET_NAME)"; 569 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FBImageGallery.app/FBImageGallery"; 570 | }; 571 | name = Debug; 572 | }; 573 | E68D65991E9F7CF900F66A28 /* Release */ = { 574 | isa = XCBuildConfiguration; 575 | buildSettings = { 576 | BUNDLE_LOADER = "$(TEST_HOST)"; 577 | INFOPLIST_FILE = FBImageGalleryTests/Info.plist; 578 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 579 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 580 | PRODUCT_BUNDLE_IDENTIFIER = com.slack.com.FBImageGalleryTests; 581 | PRODUCT_NAME = "$(TARGET_NAME)"; 582 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FBImageGallery.app/FBImageGallery"; 583 | }; 584 | name = Release; 585 | }; 586 | E68D659B1E9F7CF900F66A28 /* Debug */ = { 587 | isa = XCBuildConfiguration; 588 | buildSettings = { 589 | INFOPLIST_FILE = FBImageGalleryUITests/Info.plist; 590 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 591 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 592 | PRODUCT_BUNDLE_IDENTIFIER = com.slack.com.FBImageGalleryUITests; 593 | PRODUCT_NAME = "$(TARGET_NAME)"; 594 | TEST_TARGET_NAME = FBImageGallery; 595 | }; 596 | name = Debug; 597 | }; 598 | E68D659C1E9F7CF900F66A28 /* Release */ = { 599 | isa = XCBuildConfiguration; 600 | buildSettings = { 601 | INFOPLIST_FILE = FBImageGalleryUITests/Info.plist; 602 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 603 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 604 | PRODUCT_BUNDLE_IDENTIFIER = com.slack.com.FBImageGalleryUITests; 605 | PRODUCT_NAME = "$(TARGET_NAME)"; 606 | TEST_TARGET_NAME = FBImageGallery; 607 | }; 608 | name = Release; 609 | }; 610 | /* End XCBuildConfiguration section */ 611 | 612 | /* Begin XCConfigurationList section */ 613 | E68D65621E9F7CF900F66A28 /* Build configuration list for PBXProject "FBImageGallery" */ = { 614 | isa = XCConfigurationList; 615 | buildConfigurations = ( 616 | E68D65921E9F7CF900F66A28 /* Debug */, 617 | E68D65931E9F7CF900F66A28 /* Release */, 618 | ); 619 | defaultConfigurationIsVisible = 0; 620 | defaultConfigurationName = Release; 621 | }; 622 | E68D65941E9F7CF900F66A28 /* Build configuration list for PBXNativeTarget "FBImageGallery" */ = { 623 | isa = XCConfigurationList; 624 | buildConfigurations = ( 625 | E68D65951E9F7CF900F66A28 /* Debug */, 626 | E68D65961E9F7CF900F66A28 /* Release */, 627 | ); 628 | defaultConfigurationIsVisible = 0; 629 | defaultConfigurationName = Release; 630 | }; 631 | E68D65971E9F7CF900F66A28 /* Build configuration list for PBXNativeTarget "FBImageGalleryTests" */ = { 632 | isa = XCConfigurationList; 633 | buildConfigurations = ( 634 | E68D65981E9F7CF900F66A28 /* Debug */, 635 | E68D65991E9F7CF900F66A28 /* Release */, 636 | ); 637 | defaultConfigurationIsVisible = 0; 638 | defaultConfigurationName = Release; 639 | }; 640 | E68D659A1E9F7CF900F66A28 /* Build configuration list for PBXNativeTarget "FBImageGalleryUITests" */ = { 641 | isa = XCConfigurationList; 642 | buildConfigurations = ( 643 | E68D659B1E9F7CF900F66A28 /* Debug */, 644 | E68D659C1E9F7CF900F66A28 /* Release */, 645 | ); 646 | defaultConfigurationIsVisible = 0; 647 | defaultConfigurationName = Release; 648 | }; 649 | /* End XCConfigurationList section */ 650 | }; 651 | rootObject = E68D655F1E9F7CF900F66A28 /* Project object */; 652 | } 653 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/project.xcworkspace/xcuserdata/SLAVISHM.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery.xcodeproj/project.xcworkspace/xcuserdata/SLAVISHM.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/project.xcworkspace/xcuserdata/avish057.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery.xcodeproj/project.xcworkspace/xcuserdata/avish057.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/project.xcworkspace/xcuserdata/gh.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery.xcodeproj/project.xcworkspace/xcuserdata/gh.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/SLAVISHM.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | FBImageGallery.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/avish057.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/avish057.xcuserdatad/xcschemes/FBImageGallery.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/avish057.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | FBImageGallery.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E68D65661E9F7CF900F66A28 16 | 17 | primary 18 | 19 | 20 | E68D657F1E9F7CF900F66A28 21 | 22 | primary 23 | 24 | 25 | E68D658A1E9F7CF900F66A28 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/gh.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/gh.xcuserdatad/xcschemes/FBImageGallery.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /FBImageGallery.xcodeproj/xcuserdata/gh.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | FBImageGallery.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E68D65661E9F7CF900F66A28 16 | 17 | primary 18 | 19 | 20 | E68D657F1E9F7CF900F66A28 21 | 22 | primary 23 | 24 | 25 | E68D658A1E9F7CF900F66A28 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /FBImageGallery/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | @property (nonatomic) BOOL isPan; 15 | @property (nonatomic) NSInteger imgIndex; 16 | 17 | +(AppDelegate *)appDelegate; 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /FBImageGallery/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | +(AppDelegate *)appDelegate{ 51 | return (AppDelegate *)[[UIApplication sharedApplication] delegate]; 52 | } 53 | @end 54 | -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image1.imageset/Image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image1.imageset/Image1.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image2.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image2.imageset/Image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image2.imageset/Image2.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image3.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image3.imageset/Image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image3.imageset/Image3.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image4.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image4.imageset/Image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image4.imageset/Image4.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image5.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image5.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image5.imageset/Image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image5.imageset/Image5.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image6.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image6.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image6.imageset/Image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image6.imageset/Image6.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image7.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Image7.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/Image7.imageset/Image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/Image7.imageset/Image7.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/cross.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "cross@1x.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "cross@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "cross@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/cross.imageset/cross@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/cross.imageset/cross@1x.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/cross.imageset/cross@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/cross.imageset/cross@2x.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/cross.imageset/cross@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/cross.imageset/cross@3x.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/default_propertyImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "default_propertyImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "default_propertyImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/default_propertyImage.imageset/default_propertyImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/default_propertyImage.imageset/default_propertyImage.png -------------------------------------------------------------------------------- /FBImageGallery/Assets.xcassets/default_propertyImage.imageset/default_propertyImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/FBImageGallery/Assets.xcassets/default_propertyImage.imageset/default_propertyImage@2x.png -------------------------------------------------------------------------------- /FBImageGallery/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /FBImageGallery/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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /FBImageGallery/Constants.h: -------------------------------------------------------------------------------- 1 | // 2 | // Constants.h 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #ifndef Constants_h 10 | #define Constants_h 11 | 12 | #import "AppDelegate.h" 13 | 14 | #define APP_DELEGATE [AppDelegate appDelegate] 15 | 16 | 17 | #endif /* Constants_h */ 18 | -------------------------------------------------------------------------------- /FBImageGallery/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 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 | -------------------------------------------------------------------------------- /FBImageGallery/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MHFacebookImageViewer.h" 11 | #import "UIImageView+MHFacebookImageViewer.h" 12 | 13 | @interface ViewController : UIViewController{ 14 | __weak IBOutlet UICollectionView *collectionObj; 15 | } 16 | 17 | 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /FBImageGallery/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "UIImageView+AFNetworking.h" 11 | 12 | @interface ViewController (){ 13 | NSMutableArray *imgsArr, *captionsArr; 14 | } 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | // Do any additional setup after loading the view, typically from a nib. 23 | 24 | imgsArr = [[NSMutableArray alloc] init]; 25 | captionsArr = [[NSMutableArray alloc] init]; 26 | 27 | 28 | imgsArr = [@[@"https://www.gstatic.com/webp/gallery/1.jpg", @"https://www.gstatic.com/webp/gallery/2.jpg", @"https://www.gstatic.com/webp/gallery/3.jpg", @"https://www.gstatic.com/webp/gallery/4.jpg", @"https://www.gstatic.com/webp/gallery3/5.png"] mutableCopy]; 29 | 30 | for (int i = 1; i <= 7; i++) { 31 | [captionsArr addObject:[NSString stringWithFormat:@"Image%d", i]]; 32 | } 33 | 34 | [collectionObj setDataSource:self]; 35 | [collectionObj setDelegate:self]; 36 | [collectionObj reloadData]; 37 | } 38 | 39 | 40 | - (void)didReceiveMemoryWarning { 41 | [super didReceiveMemoryWarning]; 42 | // Dispose of any resources that can be recreated. 43 | } 44 | 45 | -(void)viewWillAppear:(BOOL)animated{ 46 | [self addNotification]; 47 | [super viewWillAppear:animated]; 48 | } 49 | 50 | -(void)addNotification{ 51 | [[NSNotificationCenter defaultCenter] removeObserver:self name:@"GalleryClosed" object:nil]; 52 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageScroll:) name:@"GalleryClosed" object:nil]; 53 | } 54 | 55 | -(void)imageScroll:(NSNotification *)notify{ 56 | [collectionObj scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:[notify.object integerValue] inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO]; 57 | 58 | } 59 | 60 | #pragma mark - UICollectionView datasource and delegates 61 | 62 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 63 | return CGSizeMake(self.view.bounds.size.width, collectionView.frame.size.height); 64 | } 65 | 66 | -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 67 | return imgsArr.count; 68 | } 69 | 70 | - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 71 | static NSString *cellIdentifier = @"ImageCollectionCell"; 72 | UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 73 | 74 | __weak UIImageView *img = (UIImageView *)[cell.contentView viewWithTag:1]; 75 | UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 76 | [activity startAnimating]; 77 | [activity setFrame:CGRectMake(self.view.bounds.size.width/2 - activity.frame.size.width / 2, img.frame.origin.y + (collectionView.frame.size.height / 2), activity.frame.size.width, activity.frame.size.height)]; 78 | [activity setHidesWhenStopped:true]; 79 | [img addSubview:activity]; 80 | [img setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:imgsArr[indexPath.row]]] placeholderImage:[UIImage imageNamed:@"default_propertyImage"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 81 | [activity stopAnimating]; 82 | [img setImage:image]; 83 | NSLog(@"success"); 84 | } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 85 | [activity stopAnimating]; 86 | NSLog(@"failure"); 87 | }]; 88 | 89 | [img setupImageViewerWithDatasource:self initialIndex:indexPath.item onOpen:^{ 90 | 91 | // write code when image is opened 92 | 93 | } onClose:^{ 94 | // wirte code when image is closed 95 | 96 | }]; 97 | 98 | return cell; 99 | } 100 | 101 | 102 | #pragma mark - MHFaceBookViewer Protocol 103 | 104 | -(NSInteger)numberImagesForImageViewer:(MHFacebookImageViewer *)imageViewer{ 105 | return imgsArr.count; 106 | } 107 | 108 | -(UIImage *)imageDefaultAtIndex:(NSInteger)index imageViewer:(MHFacebookImageViewer *)imageViewer{ 109 | return [UIImage imageNamed:@"default_propertyImage"]; 110 | } 111 | 112 | -(NSURL *)imageURLAtIndex:(NSInteger)index imageViewer:(MHFacebookImageViewer *)imageViewer{ 113 | 114 | [[NSNotificationCenter defaultCenter] postNotificationName:@"captionNotification" object:nil userInfo:@{@"caption": captionsArr[index], @"imageIndex": [NSString stringWithFormat:@"%ld", (long)index + 1], @"imagesCount": [NSString stringWithFormat:@"%lu", (unsigned long)imgsArr.count]}]; 115 | 116 | return [NSURL URLWithString:[NSString stringWithFormat:@"%@", imgsArr[index]]]; 117 | } 118 | 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /FBImageGallery/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // FBImageGallery 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /FBImageGalleryTests/FBImageGalleryTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // FBImageGalleryTests.m 3 | // FBImageGalleryTests 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FBImageGalleryTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation FBImageGalleryTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /FBImageGalleryTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /FBImageGalleryUITests/FBImageGalleryUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // FBImageGalleryUITests.m 3 | // FBImageGalleryUITests 4 | // 5 | // Created by gh on 4/13/17. 6 | // Copyright © 2017 Slack. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FBImageGalleryUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation FBImageGalleryUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /FBImageGalleryUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Avish Manocha 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MHFBImageViewController/MHFacebookImageViewer.h: -------------------------------------------------------------------------------- 1 | // 2 | // MHFacebookImageViewer.h 3 | // Version 2.0 4 | // 5 | // Copyright (c) 2013 Michael Henry Pantaleon (http://www.iamkel.net). All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import 26 | 27 | typedef void (^MHFacebookImageViewerOpeningBlock)(void); 28 | typedef void (^MHFacebookImageViewerClosingBlock)(void); 29 | 30 | 31 | @class MHFacebookImageViewer; 32 | @protocol MHFacebookImageViewerDatasource 33 | @required 34 | - (NSInteger) numberImagesForImageViewer:(MHFacebookImageViewer*) imageViewer; 35 | - (NSURL*) imageURLAtIndex:(NSInteger)index imageViewer:(MHFacebookImageViewer*) imageViewer; 36 | - (UIImage*) imageDefaultAtIndex:(NSInteger)index imageViewer:(MHFacebookImageViewer*) imageViewer; 37 | @end 38 | 39 | 40 | @interface MHFacebookImageViewer : UIViewController 41 | @property (weak, readonly, nonatomic) UIViewController *rootViewController; 42 | @property (nonatomic,strong) NSURL * imageURL; 43 | @property (nonatomic,strong) UIImageView * senderView; 44 | @property (nonatomic,weak) MHFacebookImageViewerOpeningBlock openingBlock; 45 | @property (nonatomic,weak) MHFacebookImageViewerClosingBlock closingBlock; 46 | @property (nonatomic,weak) id imageDatasource; 47 | @property (nonatomic,assign) NSInteger initialIndex; 48 | 49 | -(void)addTapGesture:(UIButton *)btn; 50 | - (void)presentFromRootViewController; 51 | - (void)presentFromViewController:(UIViewController *)controller; 52 | @end 53 | 54 | @interface MHFacebookImageViewerTapGestureRecognizer : UITapGestureRecognizer 55 | @property(nonatomic,strong) NSURL * imageURL; 56 | @property(nonatomic,strong) MHFacebookImageViewerOpeningBlock openingBlock; 57 | @property(nonatomic,strong) MHFacebookImageViewerClosingBlock closingBlock; 58 | @property(nonatomic,weak) id imageDatasource; 59 | @property(nonatomic,assign) NSInteger initialIndex; 60 | 61 | @end 62 | 63 | #pragma mark - UIImageView Category 64 | 65 | //@interface UIImageView(MHFacebookImageViewer) 66 | // 67 | ////-(void)setImageBrowser:(MHFacebookImageViewer *)imageBrowser; 68 | ////-(MHFacebookImageViewer *)imageBrowser; 69 | //- (void) setupImageViewer; 70 | //- (void) setupImageViewerWithCompletionOnOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 71 | //- (void) setupImageViewerWithImageURL:(NSURL*)url; 72 | //- (void) setupImageViewerWithImageURL:(NSURL *)url onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 73 | //- (void) setupImageViewerWithDatasource:(id)imageDatasource onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 74 | //- (void) setupImageViewerWithDatasource:(id)imageDatasource initialIndex:(NSInteger)initialIndex onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 75 | //- (void)removeImageViewer; 76 | //@end 77 | -------------------------------------------------------------------------------- /MHFBImageViewController/Resources/Done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/MHFBImageViewController/Resources/Done.png -------------------------------------------------------------------------------- /MHFBImageViewController/Resources/Done@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avish07/FBImageGallery/78d72865aaf13eaafcf26f24077efdfbf748cede/MHFBImageViewController/Resources/Done@2x.png -------------------------------------------------------------------------------- /MHFBImageViewController/UIImageView+MHFacebookImageViewer.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+MHFacebookImageViewer.h 3 | // FBImageViewController_Demo 4 | // 5 | // Created by Jhonathan Wyterlin on 14/03/15. 6 | // Copyright (c) 2015 Michael Henry Pantaleon. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MHFacebookImageViewer.h" 11 | 12 | @interface UIImageView (MHFacebookImageViewer) 13 | 14 | - (void) setupImageViewer; 15 | - (void) setupImageViewerWithCompletionOnOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 16 | - (void) setupImageViewerWithImageURL:(NSURL*)url; 17 | - (void) setupImageViewerWithImageURL:(NSURL *)url onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 18 | - (void) setupImageViewerWithDatasource:(id)imageDatasource onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 19 | - (void) setupImageViewerWithDatasource:(id)imageDatasource initialIndex:(NSInteger)initialIndex onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close; 20 | - (void)removeImageViewer; 21 | @property (retain, nonatomic) MHFacebookImageViewer *imageBrowser; 22 | @end -------------------------------------------------------------------------------- /MHFBImageViewController/UIImageView+MHFacebookImageViewer.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+MHFacebookImageViewer.m 3 | // FBImageViewController_Demo 4 | // 5 | // Created by Jhonathan Wyterlin on 14/03/15. 6 | // Copyright (c) 2015 Michael Henry Pantaleon. All rights reserved. 7 | // 8 | 9 | #import "UIImageView+MHFacebookImageViewer.h" 10 | #import 11 | @interface UIImageView() 12 | 13 | @property (nonatomic, assign) MHFacebookImageViewer *imageBrowser; 14 | 15 | @end 16 | 17 | static char kImageBrowserKey; 18 | 19 | #pragma mark - UIImageView Category 20 | @implementation UIImageView (MHFacebookImageViewer) 21 | 22 | #pragma mark - Initializer for UIImageView 23 | - (void) setupImageViewer { 24 | [self setupImageViewerWithCompletionOnOpen:nil onClose:nil]; 25 | } 26 | 27 | - (void) setupImageViewerWithCompletionOnOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close { 28 | [self setupImageViewerWithImageURL:nil onOpen:open onClose:close]; 29 | } 30 | 31 | - (void) setupImageViewerWithImageURL:(NSURL*)url { 32 | [self setupImageViewerWithImageURL:url onOpen:nil onClose:nil]; 33 | } 34 | 35 | 36 | - (void) setupImageViewerWithImageURL:(NSURL *)url onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close{ 37 | self.userInteractionEnabled = YES; 38 | MHFacebookImageViewerTapGestureRecognizer * tapGesture = [[MHFacebookImageViewerTapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)]; 39 | tapGesture.imageURL = url; 40 | tapGesture.openingBlock = open; 41 | tapGesture.closingBlock = close; 42 | [self addGestureRecognizer:tapGesture]; 43 | tapGesture = nil; 44 | } 45 | 46 | 47 | - (void) setupImageViewerWithDatasource:(id)imageDatasource onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close { 48 | [self setupImageViewerWithDatasource:imageDatasource initialIndex:0 onOpen:open onClose:close]; 49 | } 50 | 51 | - (void) setupImageViewerWithDatasource:(id)imageDatasource initialIndex:(NSInteger)initialIndex onOpen:(MHFacebookImageViewerOpeningBlock)open onClose:(MHFacebookImageViewerClosingBlock)close{ 52 | self.userInteractionEnabled = YES; 53 | MHFacebookImageViewerTapGestureRecognizer * tapGesture = [[MHFacebookImageViewerTapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)]; 54 | tapGesture.imageDatasource = imageDatasource; 55 | tapGesture.openingBlock = open; 56 | tapGesture.closingBlock = close; 57 | tapGesture.initialIndex = initialIndex; 58 | [self addGestureRecognizer:tapGesture]; 59 | tapGesture = nil; 60 | 61 | // if (initialIndex == 3) { 62 | // [self didTap:tapGesture]; 63 | // } 64 | 65 | 66 | } 67 | 68 | 69 | #pragma mark - Handle Tap 70 | - (void) didTap:(MHFacebookImageViewerTapGestureRecognizer*)gestureRecognizer { 71 | 72 | [self setImageBrowser:[[MHFacebookImageViewer alloc]init]]; 73 | [[self imageBrowser] setSenderView: self]; 74 | [[self imageBrowser] setImageURL:gestureRecognizer.imageURL]; 75 | [[self imageBrowser] setOpeningBlock:gestureRecognizer.openingBlock]; 76 | [[self imageBrowser] setClosingBlock:gestureRecognizer.closingBlock]; 77 | [[self imageBrowser] setImageDatasource:gestureRecognizer.imageDatasource]; 78 | [[self imageBrowser] setInitialIndex:gestureRecognizer.initialIndex]; 79 | 80 | if(self.image) 81 | [self.imageBrowser presentFromRootViewController]; 82 | } 83 | 84 | - (void) dealloc { 85 | 86 | } 87 | 88 | #pragma mark Removal 89 | -(void)removeImageViewer { 90 | 91 | [[[self imageBrowser] view] removeFromSuperview]; 92 | [[self imageBrowser] removeFromParentViewController]; 93 | 94 | for (UIGestureRecognizer * gesture in self.gestureRecognizers) { 95 | 96 | if ( [gesture isKindOfClass:[MHFacebookImageViewerTapGestureRecognizer class]] ) { 97 | 98 | [self removeGestureRecognizer:gesture]; 99 | 100 | MHFacebookImageViewerTapGestureRecognizer * tapGesture = (MHFacebookImageViewerTapGestureRecognizer *)gesture; 101 | tapGesture.imageURL = nil; 102 | tapGesture.openingBlock = nil; 103 | tapGesture.closingBlock = nil; 104 | 105 | } 106 | 107 | } 108 | 109 | } 110 | 111 | -(void)setImageBrowser:(MHFacebookImageViewer *)imageBrowser { 112 | objc_setAssociatedObject(self, &kImageBrowserKey, imageBrowser, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 113 | } 114 | 115 | -(MHFacebookImageViewer *)imageBrowser { 116 | return objc_getAssociatedObject(self, &kImageBrowserKey); 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FBImageGallery 2 | 3 | FBImageGallery is custom gallery which includes :- 4 | 5 | for single image. 6 | for multiple images in UICollection view. 7 | for custom text and controls in image gallery. 8 | --------------------------------------------------------------------------------