Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. - (void) getData
  2. {
  3. NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"GET" URLString:@"http://----------" parameters:nil error:nil];
  4.  
  5. AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  6.  
  7. req.timeoutInterval= 15;
  8. [req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  9. [req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  10.  
  11. self.dataTask = [manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error)
  12. {
  13.  
  14. if (!error)
  15. {
  16. NSLog(@"Reply JSON >>>>>> responseObject <<<<<: %@", responseObject);
  17.  
  18.  
  19. if ([responseObject isKindOfClass:[NSDictionary class]])
  20. {
  21. if (self.delegate && [self.delegate respondsToSelector:@selector(success:)]) {
  22. [self.delegate success:responseObject];
  23. }
  24. // self.colorView.backgroundColor = [UIColor blueColor];
  25. return;
  26. }
  27. else
  28. {
  29. NSLog(@"Error No dictionary: %@, %@, %@", error, response, responseObject);
  30. {
  31. // self.colorView.backgroundColor = [UIColor redColor];
  32. [self.delegate error:error];
  33. return;
  34. }
  35.  
  36. }
  37. }
  38. else
  39. {
  40. NSLog(@"Error: %@, %@, %@", error, response, responseObject);
  41. [self.delegate error:error];
  42. return;
  43.  
  44. }
  45.  
  46. }];
  47.  
  48. [self.dataTask resume];
  49.  
  50. if (self.cancelRequest) {
  51. [self.dataTask cancel];
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement