diff options
author | Vitaly Takmazov | 2019-03-21 01:23:22 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-21 14:08:52 +0300 |
commit | 1871f3d5298efb978be825b03fd9c20ff4c204a8 (patch) | |
tree | 61e4683669ce240b28b066f5cc30556fcaeff85c /Juick/APIClient.m | |
parent | 458e55b9cddcadb2bbbe3fb4002f06a5744b84c0 (diff) |
APIClient fetchImageWithURL
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r-- | Juick/APIClient.m | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index d3bd248..fdc4005 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -12,6 +12,7 @@ @interface APIClient() @property(nonatomic, readwrite) AFHTTPSessionManager *manager; @property(nonatomic, strong) NSOperationQueue *backgroundQueue; +@property(nonatomic, strong) NSURLSession *urlSession; @end @implementation APIClient @@ -36,6 +37,7 @@ self.dateFormatter = [[NSDateFormatter alloc] init]; self.dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; [self.dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; + _urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; } return self; } @@ -203,6 +205,17 @@ } +- (void)fetchImageWithURL:(NSURL *)url callback:(void (^)(NSData *))callback { + NSURLSessionDataTask *dataTask = [self.urlSession dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + callback(data); + }]; + }]; + [self.backgroundQueue addOperationWithBlock:^{ + [dataTask resume]; + }]; +} + +(NSString *) messagesUrl { return @"messages"; } |