Last active
December 30, 2015 11:29
-
-
Save cemuzunlar/7822643 to your computer and use it in GitHub Desktop.
HttpManagerSingleton
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)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))handler { | |
[NSURLConnection request:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { | |
if (err) { | |
[self showRetryDialog:^(bool retryClicked, bool cancelClicked) { | |
if (retryClicked) { | |
[self sendAsynchronousRequest:request queue:queue completionHandler:handler]; | |
} | |
else { | |
handler(nil, nil, nil); | |
} | |
} | |
} | |
else { | |
handler(response, data, error); | |
} | |
}]; | |
} | |
+ (void)showRetryDialog:(void (^)(bool, bool))handler { | |
// When clicked retry: | |
handler(true, false); | |
// When cancel clicked | |
handler(false, true); | |
} | |
// Ornek kullanım: | |
[HttpManagerSingleton sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { | |
if (response == nil) { | |
NSLog("Cancelled."); | |
} | |
else { | |
NSLog("Succeeded."); | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment