summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Juick/APIClient.m36
1 files changed, 19 insertions, 17 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index fdc4005..dcc72a8 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -53,26 +53,28 @@
}
-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback {
- [self.backgroundQueue addOperationWithBlock:^{
- [self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSMutableArray *messages = [NSMutableArray new];
- [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [messages addObject:[Message fromJSON:obj]];
- }];
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- callback(messages, nil);
- }];
-
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
- NSLog(@"REST Error: %@", error);
- NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
- if (statusCode == 401) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ [self.backgroundQueue addOperationWithBlock:^{
+ [self.manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ NSMutableArray *messages = [NSMutableArray new];
+ [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+ [messages addObject:[Message fromJSON:obj]];
+ }];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- callback(nil, [[NSError alloc] initWithDomain:@"JuickErrorDomain" code:401 userInfo:nil]);
+ callback(messages, nil);
}];
- }
+
+ } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
+ NSLog(@"REST Error: %@", error);
+ NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
+ if (statusCode == 401) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ callback(nil, [[NSError alloc] initWithDomain:@"JuickErrorDomain" code:401 userInfo:nil]);
+ }];
+ }
+ }];
}];
- }];
+ });
}
-(void) postMessage:(NSString *)text result:(void (^)(Message *, NSError *))callback {