Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rtalwarhike
Created December 9, 2016 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtalwarhike/a9a4d5a37e2b9abd1fa367c35b28e174 to your computer and use it in GitHub Desktop.
Save rtalwarhike/a9a4d5a37e2b9abd1fa367c35b28e174 to your computer and use it in GitHub Desktop.
objective c network GET
-(void)get:(NSString *)url withCallback:(void (^)(NSError *, NSData* ))completionHandler {
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
req.HTTPMethod = @"GET";
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfig.requestCachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig];
NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
completionHandler(error,data);
}];
[task resume];
}
+(NSString*)user_documents_directory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
NSString *dirPath = [paths objectAtIndex:0];
return dirPath;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment