Abhishek Banthia
9 years ago
12 changed files with 332 additions and 205 deletions
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
//
|
||||
// CLAPI.h
|
||||
// Clocker
|
||||
//
|
||||
// Created by Abhishek Banthia on 1/10/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h> |
||||
|
||||
@interface CLAPI : NSObject |
||||
|
||||
+ (void)dataTaskWithServicePath:(NSString *)path |
||||
bySender:(id)sender |
||||
withCompletionBlock:(void (^)(NSError *error, NSDictionary *dictionary))completionBlock; |
||||
|
||||
+ (BOOL)isUserConnectedToInternet; |
||||
|
||||
@end |
@ -0,0 +1,82 @@
|
||||
// |
||||
// CLAPI.m |
||||
// Clocker |
||||
// |
||||
// Created by Abhishek Banthia on 1/10/16. |
||||
// |
||||
// |
||||
|
||||
#import "CLAPI.h" |
||||
#import "Reachability.h" |
||||
|
||||
@implementation CLAPI |
||||
|
||||
+ (void)dataTaskWithServicePath:(NSString *)path |
||||
bySender:(id)sender |
||||
withCompletionBlock:(void (^)(NSError *error, NSDictionary *dictionary))completionBlock |
||||
{ |
||||
|
||||
__block NSDictionary *responseDictionary = [NSDictionary dictionary]; |
||||
|
||||
NSView *currentView = [sender view]; |
||||
|
||||
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; |
||||
|
||||
sessionConfig.timeoutIntervalForRequest = 20; |
||||
|
||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig]; |
||||
|
||||
NSError *error; |
||||
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", path]]; |
||||
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; |
||||
[request setHTTPMethod:@"GET"]; |
||||
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; |
||||
|
||||
NSURLSessionDataTask *dataTask = [session |
||||
dataTaskWithRequest:request |
||||
completionHandler:^(NSData *data, |
||||
NSURLResponse *response, |
||||
NSError *error) |
||||
{ |
||||
|
||||
/*Check if any error. If nil then proceed*/ |
||||
if (error == nil) |
||||
{ |
||||
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response; |
||||
if (httpResp.statusCode == 200) |
||||
{ |
||||
responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; |
||||
completionBlock(error, responseDictionary); |
||||
} |
||||
} |
||||
/*Error is not nil. Show error*/ |
||||
else |
||||
{ |
||||
completionBlock(error, nil); |
||||
|
||||
} |
||||
}]; |
||||
|
||||
[dataTask resume]; |
||||
|
||||
} |
||||
|
||||
+ (BOOL)isUserConnectedToInternet |
||||
{ |
||||
Reachability *reachability = [Reachability reachabilityForInternetConnection]; |
||||
NetworkStatus networkStatus = [reachability currentReachabilityStatus]; |
||||
|
||||
if (networkStatus == NotReachable) |
||||
{ |
||||
return NO; |
||||
} |
||||
|
||||
return YES; |
||||
} |
||||
|
||||
|
||||
@end |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 249 B |
@ -0,0 +1,21 @@
|
||||
{ |
||||
"images" : [ |
||||
{ |
||||
"idiom" : "universal", |
||||
"filename" : "Untitled.png", |
||||
"scale" : "1x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "2x" |
||||
}, |
||||
{ |
||||
"idiom" : "universal", |
||||
"scale" : "3x" |
||||
} |
||||
], |
||||
"info" : { |
||||
"version" : 1, |
||||
"author" : "xcode" |
||||
} |
||||
} |
After Width: | Height: | Size: 249 B |
Loading…
Reference in new issue