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 download a file and save it to the documents directory with AFNetworking?

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@”…”]]; AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@”filename”]; operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@”Successfully downloaded file to %@”, path); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@”Error: %@”, error); }]; [operation start];

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

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); }];

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

afnetworking 3.0 Migration: how to POST with headers and HTTP Body

Another way to call a POST method with AFNetworking 3.0 is: AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager.requestSerializer setValue:@”application/json” forHTTPHeaderField:@”Content-Type”]; [manager POST:url parameters:parametersDictionary progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@”success!”); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@”error: %@”, error); }]; Hope it helps!

Can AFNetworking return data synchronously (inside a block)?

To block the execution of the main thread until the operation completes, you could do [operation waitUntilFinished] after it’s added to the operation queue. In this case, you wouldn’t need the return in the block; setting the __block variable would be enough. That said, I’d strongly discourage forcing asynchronous operations to synchronous methods. It’s tricky … Read more

Cannot install Alamofire in new Xcode Project. “No Such module Alamofire”

Make sure you haven’t added any files from Alamofire to your project except for the Alamofire.xcodeproj Here is step by step instruction: Download and unarchive Alamofire Copy the root folder of Alamofire to any subfolder of your project. Libs, for example. Drag and drop Alamofire.xcodeproj to your Xcode project Open project settings of your project, … Read more

AFNetworking and background transfers

A couple of thoughts: You have to make sure you do the necessary coding outlined in the Handling iOS Background Activity section of the URL Loading System Programming Guide says: If you are using NSURLSession in iOS, your app is automatically relaunched when a download completes. Your app’s application:handleEventsForBackgroundURLSession:completionHandler: app delegate method is responsible for … Read more