AFNetworking and Cookies

You do not need to bother with NSUserDefaults nor any keychain wrapper if you use NSURLCredential. Indeed NSURLCredential is much simpler to use, as it allows you to store both username and password in the keychain in two lines of code. Your code would be something like that once the user is logged in: NSURLCredential … Read more

iOS Image upload via AFNetworking 2.0

I ended up using the multi-part request UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; NSData *imageData = UIImageJPEGRepresentation(image, 0.5); AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@”foo”: @”bar”}; [manager POST:@”http://example.com/resources.json” parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFormData:imageData name:@”image”]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@”Success: %@”, responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@”Error: %@”, error); }];