I’m getting compiler warnings with AFNetworking, but shouldn’t be. How do I fix it?

I’m not sure if you’re using CocoaPods or not but this is a known issue being tracked on the AFNetworking Github page. I was able to fix this by adding the correct import statements directly to my `PROJECTNAME-Prefix.pch there I changed it to this. #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <SystemConfiguration/SystemConfiguration.h> #import <MobileCoreServices/MobileCoreServices.h> #endif If you … Read more

AFNetworking 2.0 Reachability

You’re making this more difficult than it needs to be. Try this: – (void)viewDidLoad { [super viewDidLoad]; [[AFNetworkReachabilityManager sharedManager] startMonitoring]; } – (BOOL)connected { return [AFNetworkReachabilityManager sharedManager].reachable; } If you also want to be notified when the status changes, then implement setReachabilityStatusChangeBlock.

SDURLCache with AFNetworking and offline mode not working

Well I’ve finally reached a not so ugly workaround: First If you’re using IOS5/IOS6 you can drop SDURLCache and use the native one: //Set Cache NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:URLCache]; But remember that in IOS5 https requests wont be cached in IOS6 … Read more

Better asynchronous control flow with Objective-C blocks

I created a light-weight solution for this. It’s called Sequencer and it’s up on github. It makes chaining API calls (or any other async code) easy and straightforward. Here’s an example of using AFNetworking with it: Sequencer *sequencer = [[Sequencer alloc] init]; [sequencer enqueueStep:^(id result, SequencerCompletion completion) { NSURL *url = [NSURL URLWithString:@”https://alpha-api.app.net/stream/0/posts/stream/global”]; NSURLRequest *request … Read more

AFNetworking: Handle error globally and repeat request

I use an alternative means for doing this with AFNetworking 2.0. You can subclass dataTaskWithRequest:success:failure: and wrap the passed completion block with some error checking. For example, if you’re working with OAuth, you could watch for a 401 error (expiry) and refresh your access token. – (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)urlRequest completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError … Read more

How to load image in swift using Alamofire

As authors mention in Alamofire README.md: When should I use AFNetworking? UIKit extensions, such as asynchronously loading images to UIImageView So answer to your question : So is AFNetworking is better for this task? Yes! But if still want to use vanilla Alamofire project, you can fetch image this way: Alamofire.request(.GET, “https://robohash.org/123.png”).response { (request, response, … 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

tech