{"id":16886691,"url":"https://github.com/alisoftware/ohurlloader","last_synced_at":"2025-04-11T12:38:11.987Z","repository":{"id":1313702,"uuid":"1258479","full_name":"AliSoftware/OHURLLoader","owner":"AliSoftware","description":"Class that uses blocks (new to iOS4/OSX 10.6) to make URL requests/downloads much more easier","archived":false,"fork":false,"pushed_at":"2011-01-15T22:56:31.000Z","size":127,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-25T08:51:24.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AliSoftware.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-01-15T19:22:39.000Z","updated_at":"2018-01-22T10:27:47.000Z","dependencies_parsed_at":"2022-08-16T13:05:09.187Z","dependency_job_id":null,"html_url":"https://github.com/AliSoftware/OHURLLoader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FOHURLLoader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FOHURLLoader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FOHURLLoader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AliSoftware%2FOHURLLoader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AliSoftware","download_url":"https://codeload.github.com/AliSoftware/OHURLLoader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248402453,"owners_count":21097331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:40:48.896Z","updated_at":"2025-04-11T12:38:11.966Z","avatar_url":"https://github.com/AliSoftware.png","language":"Objective-C","readme":"This class make it easier to perform URL requests by using blocks (instead of having to use a delegate and implement delegate methds).\n\n----------\n\nTo use this class, you simply have to use the commodity constructor then call one of the two \"start…\" methods, providing the blocks of code to execute on success and on error.\n\n\tNSURL* url = ...\n\tNSURLRequest* req = [NSURLRequest requestWithURL:url];\n\n\tOHURLLoader* loader = [OHURLLoader URLLoaderWithRequest:req];\n\t[loader startRequestWithCompletion:^(NSData* receivedData, NSInteger httpStatusCode) {\n\t\tNSLog(@\"Download of %@ done (statusCode:%d)\",url,statusCode);\n\t\tif (httpStatusCode == 200) {\n\t\t\t// Use comodity accessos receivedString that interpret the received NSData\n\t\t\t// using the encoding mentionned in the received response headers, if available\n\t\t\toutputTextView.text = loader.receivedString;\n\t\t} else {\n\t\t\t// Log unexpected status code\n\t\t\toutputTextView.text = [NSString stringWithFormat:@\"HTTP Status code: %d\",httpStatusCode];\n\t\t}\n\t} errorHandler:^(NSError *error) {\n\t\tNSLog(@\"Error while downloading %@: %@\",url,error);\n\t\toutputTextView.text = [error localizedDescription];\n\t}];\n\n----------\n\nIf you want to, you can also provide blocks of code to execute when receiving each chunk of data, to be notified of the progress of the download. This can be useful for long downloads, for example to update a progressbar on the screen:\n\nYou may also provide a block of code to execute when the response header is received, at which stage you are able to known the expectedContentLength or the MimeType of the response (and some other headers).\n\n\tNSURL* url = ...\n\tNSURLRequest* req = [NSURLRequest requestWithURL:url];\n\n\tOHURLLoader* loader = [OHURLLoader URLLoaderWithRequest:req];\n\t[loader startRequestWithResponseHandler:^(NSURLResponse* response) {\n\t\tNSLog(@\"Expected ContentLength: %ld\",[response expectedContentLength]);\n\t\tprogressView.progress = 0.f;\n\t} progress:^(NSUInteger receivedBytes, long long expectedBytes) {\n\t\tif (expectedBytes \u003e 0) progressView.progress = receivedBytes / (float)expectedBytes;\n\t} completion:^(NSData* receivedData, NSInteger httpStatusCode) {\n\t\tprogressView.progress = 1.f;\n\t\tNSLog(@\"Download Done (%@, statusCode:%d)\",url,httpStatusCode);\n\t\toutputTextView.text = loader.receivedString;\n\t} errorHandler:^(NSError* error) {\n\t\toutputTextView.text = [error localizedDescription];\n\t}];\n\n----------\n\nFor a more detailed usage example, see the example project in the \"OHURLLoader Example\" folder\n\n\n\nNOTE FOR PRE-OSX 10.6 and PRE-iOS 4.0\n\tThis class is primarly designed to be used with blocks, which are a new feature introduced in OSX 10.6 and iOS 4.0. \n\tAnyway, if you use earlier version of OSX/iOS, you can still use this class and listen for the NSNotifications it emits instead of using blocks.\n\tIn such case, be sure not to use NSNotifications and blocks at the same time (to avoid executing BOTH blocks and notification listener's code).\n\tYou can do this by setting the blocks to nil when using NSNotifications (or by surrounding your \"addObserver:...\" code by \"#if NS_BLOCKS_AVAILABLE\" ... \"#endif\" directives to avoid adding as an observer when using blocks)\n\nNOTE FOR AUTHENTICATION CHALLENGES \u0026 CREDENTIALS\n\tEven if this would be a feature easy to add, the current version of this class does not handle \"Authentication Challenges\" (when URL requests credentials to be accessed).\n\tThis is a design choice to keep the class API as simple as possible (as this feature is rarely used in practice)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falisoftware%2Fohurlloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falisoftware%2Fohurlloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falisoftware%2Fohurlloader/lists"}