summaryrefslogtreecommitdiff
path: root/Juick/APIClient.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r--Juick/APIClient.m13
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";
}