Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(NSArray)some function {
- AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
- success: ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
- NSArray *jsonArray =[JSON valueForKey:@"posts"];
- }
- failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {}
- }
- - (void)goFetch:(id)caller
- {
- AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
- success: ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
- [caller takeThisArrayAndShoveIt:[JSON valueForKey:@"posts"]];
- }
- failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {}
- }
- - (void)goFetch:(void(^)(NSArray *))completion
- {
- AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
- success: ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
- if( completion ) completion([JSON valueForKey:@"posts"]);
- }
- failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {}
- }
- typedef void (^Completion)(NSArray* array, NSError *error);
- -(void)someFunctionWithBlock:(Completion)block {
- AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
- success: ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
- NSArray *jsonArray =[JSON valueForKey:@"posts"];
- if (block) block(jsonArray, nil);
- }
- failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
- if (block) block(nil, error);
- }
- }
- [yourClassInstance someFunctionWithBlock:^(NSArray* array, NSError *error) {
- if (error) {
- NSLog(%@"Oops error: %@",error.localizedDescription);
- } else {
- //do what you want with the returned array here.
- }
- }];
- +(void)request:(NSString *)link parameters:(NSDictionary *)params forInstance:(id)instance returns:(SEL)returnValue
- {
- AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
- [manager GET:link
- parameters:params
- success:^(AFHTTPRequestOperation *operation, id responseObject)
- {
- [instance performSelector:returnValue withObject: responseObject];
- }
- failure:^(AFHTTPRequestOperation *operation, NSError *error)
- {
- [instance performSelector:returnValue withObject:nil];
- //NSLog(@"Error: %@", error);
- }];
- }
- - (RXCM_TroubleTypes) logic_getEnumValueOfCurrentCacheProblem
- {
- RXCM_TroubleTypes result = RXCM_HaveNotTrouble;
- NetworkStatus statusConnection = [self network_typeOfInternetConnection];
- RXCM_TypesOfInternetConnection convertedNetStatus = [RXCM convertNetworkStatusTo_TypeOfInternetConnection:statusConnection];
- BOOL isAllowed = [self someMethodWith:convertedNetStatus];
- if (isAllowed){
- return RXCM_HaveNotTrouble;
- }else {
- return RXCM_Trouble_NotSuitableTypeOfInternetConnection;
- }
- return result;
- }
- - (BOOL) isUserPermissioned:(RXCM_TypesOfInternetConnection)newType
- {
- __block BOOL isReceivedValueFromBlock = NO;
- __block BOOL result = NO;
- __block BOOL isCalledDelegateMethod = NO;
- dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
- dispatch_sync(aQueue,^{
- while (!isReceivedValueFromBlock) {
- NSLog(@"While");
- if (!isCalledDelegateMethod){
- [self.delegate rxcm_isAllowToContinueDownloadingOnNewTypeOfInternetConnection:newType
- completion:^(BOOL isContinueWorkOnNewTypeOfConnection) {
- result = isContinueWorkOnNewTypeOfConnection;
- isReceivedValueFromBlock = YES;
- }];
- isCalledDelegateMethod = YES;
- }
- [NSThread sleepForTimeInterval:0.5];
- }
- });
- return result;
- }
- - (void) rxcm_isAllowToContinueDownloadingOnNewTypeOfInternetConnection:(RXCM_TypesOfInternetConnection)newType
- completion:(void(^)(BOOL isContinueWorkOnNewTypeOfConnection))completion
- {
- __weak ViewController* weak = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert"
- message:@"to continue download on the new type of connection"
- preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *ok = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- completion(YES);
- }];
- UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- completion(NO);
- }];
- [alert addAction:cancel];
- [alert addAction:ok];
- [weak presentViewController:alert animated:YES completion:nil];
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement