AFNetworking Uploading a file

First, make sure you have the latest version of AFNetworking downloaded. AFHTTPRequestOperation +HTTPRequestOperationWithRequest:success:failure: was removed a few versions back. Instead, you can do [[AFHTTPRequestOperation alloc] initWithRequest:…] and then set the completionBlock with either the straight property accessor (operation.completionBlock = ^{…}), or with -setCompletionBlockWithSuccess:failure:. Keep in mind that completion blocks execute after the request has finished … Read more

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

How To Disable AFNetworking Cache

Cacheing is handled application-wide by NSURLCache. If you don’t set a shared cache, requests are not cached. Even with a shared NSURLCache, the default implementation on iOS does not support disk cacheing anyway. That said, unless you have a very particular reason to write your own cacheing system, I would strongly recommend against it. NSURLCache … Read more

Using AFNetworking and HTTP Basic Authentication

Answer updated for AFNetworking 2.x For AFNetworking 2.x: In 2.x, they did away with AFHTTPClient, so you’ll need to extend AFHTTPRequestOperationManager with your own class. Then, you can call that class from other code. For example, here’s a sample class that extends the AFHTTPRequestOperationManager: SBAPIManager.h: #import “AFHTTPRequestOperationManager.h” @interface SBAPIManager : AFHTTPRequestOperationManager – (void)setUsername:(NSString *)username andPassword:(NSString … Read more

List saved files in iOS documents directory in a UITableView?

Here is the method I use to get the content of a directory. -(NSArray *)listFileAtPath:(NSString *)path { //—–> LIST ALL FILES <—–// NSLog(@”LISTING ALL FILES FOUND”); int count; NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL]; for (count = 0; count < (int)[directoryContent count]; count++) { NSLog(@”File %d: %@”, (count + 1), [directoryContent objectAtIndex:count]); } return … Read more

How to set a timeout with AFNetworking

Changing the timeout interval is almost certainly not the best solution to the problem you’re describing. Instead, it seems like what you actually want is for the HTTP client to handle the network becoming unreachable, no? AFHTTPClient already has a built-in mechanism to let you know when internet connection is lost, -setReachabilityStatusChangeBlock:. Requests can take … Read more

Volunteermatch API Objective C

i am using one common methods for AFNetworking WS Calling. Uses: Call WS: NSDictionary* param = @{ @”action”:@”helloWorld”, @”query”:@”{\”name\”:\”john\”}” }; [self requestWithUrlString:@”URL” parmeters:paramDictionary success:^(NSDictionary *response) { //code For Success } failure:^(NSError *error) { // code for WS Responce failure }]; Add Two Methods: this two methods are common, you can use these common method in … Read more