Created
December 9, 2016 08:49
-
-
Save rtalwarhike/a9a4d5a37e2b9abd1fa367c35b28e174 to your computer and use it in GitHub Desktop.
objective c network GET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(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