0

I found in here that you should never use dataWithContentsOfURL.

I am new to AFNetworking. What is the correct (and simplest) way to replace dataWithContentsOfURL using AFNetworking? For example, how to replace:

NSData *data = [NSData dataWithContentsOfURL:url];
Hahnemann
  • 4,378
  • 6
  • 40
  • 64

1 Answers1

0

Sorry this is a little late, but I think this is what youre looking for (courtesy of the AFNetworking ReadMe on Github) :

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
     NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
     NSLog(@"Error: %@", error);
}];

Then, if you need to, you can then convert responseData into NSData using (source):

NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:responseObject];
Community
  • 1
  • 1
Gideon Rosenthal
  • 1,953
  • 2
  • 18
  • 16