All Projects → paulmelnikow → Afnetworking Synchronous

paulmelnikow / Afnetworking Synchronous

Licence: mit
Synchronous requests for AFNetworking 1.x, 2.x, and 3.x

Projects that are alternatives of or similar to Afnetworking Synchronous

GoogleMapsHelper
An easy to integrate Model Based Google Maps Helper (SVHTTPClient, AFNetworking) That lets you Geo Code , Reverse Geocode, Get Directions , Places Autocomplete.
Stars: ✭ 21 (-86.62%)
Mutual labels:  afnetworking
Mhdevelopexample objective c
🔥🔥🔥 iOS开发技术要点汇总,核心功能配备文档。表情键盘布局、大文件分片上传、基于MVC的基类设计、MVVM+RAC实践、微信朋友圈实现方案等。
Stars: ✭ 937 (+496.82%)
Mutual labels:  afnetworking
Lcnetwork
基于AFNetworking的网络库封装
Stars: ✭ 107 (-31.85%)
Mutual labels:  afnetworking
Dotzu-Objective-c
Dotzu Objective-c example project
Stars: ✭ 30 (-80.89%)
Mutual labels:  afnetworking
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! 🦊
Stars: ✭ 3,188 (+1930.57%)
Mutual labels:  afnetworking
Afhttpclientlogger
Configurable HTTP request logger for AFNetworking
Stars: ✭ 40 (-74.52%)
Mutual labels:  afnetworking
WormholyForObjectiveC
Network debugging made easy,This network debugging tool is developed based on the swift version of Wormholy.
Stars: ✭ 21 (-86.62%)
Mutual labels:  afnetworking
Ppnetworkhelper
AFNetworking 3.x 与YYCache封装
Stars: ✭ 1,586 (+910.19%)
Mutual labels:  afnetworking
Webhere
HTML scraping for Objective-C.
Stars: ✭ 16 (-89.81%)
Mutual labels:  afnetworking
Bdboauth1manager
OAuth 1.0a library for AFNetworking 2.x
Stars: ✭ 101 (-35.67%)
Mutual labels:  afnetworking
HKHttpManager
轻量级的中大型项目AFNetworking高级封装
Stars: ✭ 20 (-87.26%)
Mutual labels:  afnetworking
Hlnetworking
基于AFNetworking的高阶网络请求管理器
Stars: ✭ 276 (+75.8%)
Mutual labels:  afnetworking
Hqmnetworking
基于AFN3.x核心类AFURLSessionManager封装的网络请求,支持 HTTPS 请求验证,可以配置请求头,支持多图上传并可选带进度回调,支持 block、delegate(代理) 请求回调,详见
Stars: ✭ 49 (-68.79%)
Mutual labels:  afnetworking
SSJNetWork
对AFNetWorking 二次封装 实现自动取消网络请求,网络请求缓冲,网络请求日志详细打印(代码还有不成熟的地方,如使用请下载到本地使用,如果问题,好及时修改)
Stars: ✭ 31 (-80.25%)
Mutual labels:  afnetworking
Wwnetworkhelper
AFN层级更高的网络请求API
Stars: ✭ 111 (-29.3%)
Mutual labels:  afnetworking
AJNetworking
AFNetworking 3.0 版本的封装,结合MJExtension框架处理JSON序列化问题
Stars: ✭ 35 (-77.71%)
Mutual labels:  afnetworking
Xmnetworking
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
Stars: ✭ 980 (+524.2%)
Mutual labels:  afnetworking
Pgnetworkhelper
PINCache做为AFNetworking缓存层,将AFNetworking请求的数据缓存起来,支持取消当前网络请求,以及取消所有的网络请求,除了常用的Get,Post方法,也将上传图片以及下载文件进行了封装,同样支持同步请求,使用方法极其简单。
Stars: ✭ 131 (-16.56%)
Mutual labels:  afnetworking
Opensource
♨️ 分享GitHub优秀开源项目和主流开发使用的网站、解决问题方案收集以及学习网站或资料,涵盖了iOS, macOS X, Blockchain, Flutter, Weex, H5, Games, C++, Script等多方面的内容,其中iOS大致包涵以下内容:音视频;IM和直播;逆向开发;图像相关(OpenGL, Metal, GPUImage);内购(IAP), ApplePay和第三方支付;安全攻防和应用加固, 数据安全和算法;常用第三方库;导航栏和状态栏;侧边菜单;数据持久;蓝牙, 手势指纹面容ID解锁, 图片浏览器, 扫码, 下拉和上拉刷新, 指示器, Toast, Menu, Sensor, Privacy, WebView和进度条, 动画, 选择器, 搜索, 分享, 图片验证码, 设备相关信息, 广告, 高仿项目及Demo等。
Stars: ✭ 123 (-21.66%)
Mutual labels:  afnetworking
Mvvmdemo
MVVMDemo With ReactiveCocoa
Stars: ✭ 60 (-61.78%)
Mutual labels:  afnetworking

AFNetworking-Synchronous

A minimal category which extends AFNetworking to support synchronous requests.

Version License Platform Downloads Build

It's synchronous

Usage

3.x

  pod 'AFNetworking', '~> 3.0'
  pod 'AFNetworking-Synchronous/3.x'
#import <AFNetworking.h>
#import <AFHTTPSessionManager+Synchronous.h>

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSError *error = nil;
NSData *result = [manager syncGET:@"/document/123"
                       parameters:paramDict
                             task:NULL
                            error:&error];

Your synchronous request will never return if it is dispatched on the session manager's completion queue.

You really should not perform a synchronous network request on the main thread on iOS, as it's likely to cause a crash when run outside the debugger. You probably should not on OS X either, as it's likely to cause lags in the UI.

If you must do so, create a separate queue for the completion handlers:

manager.completionQueue = dispatch_queue_create("AFNetworking+Synchronous", NULL);

2.x

  pod 'AFNetworking', '~> 2.0'
  pod 'AFNetworking-Synchronous/2.x'
#import <AFNetworking.h>
#import <AFHTTPRequestOperationManager+Synchronous.h>

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSError *error = nil;
NSData *result = [manager syncGET:@"/document/123"
                       parameters:paramDict
                        operation:NULL
                            error:&error];

Currently there is no support for AFHTTPSessionManager.

1.x

  pod 'AFNetworking', '~> 1.0'
  pod 'AFNetworking-Synchronous/1.x'
#import <AFNetworking.h>
#import <AFHTTPRequestOperationManager+Synchronous.h>

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:...];
NSError *error = nil;
NSData *result = [client synchronouslyGetPath:@"/document/123"
                                   parameters:paramDict
                                    operation:NULL
                                        error:&error];

Discussion

First, consider adopting an asynchronous design

Before you decide to use this category, consider whether you can adopt an asynchronous design instead. As @mattt wrote, asynchronism a tough thing to get your head around, but it's well worth the mental overhead. Rather than creating methods that fetch and return network data, use blocks or delegate methods to call back with the results when you have them.

Using the asynchronous API has many advantages:

  • When you start an operation on the main thread, you return control to the run loop immediately, so your UI can remains responsive. Blocking the main thread for a long time is never a good idea. "Be responsive," Apple urges in the OS X user experience guidelines. Asynchronous network operations allow you to do that.
  • AFNetworking makes asynchronous code easy to write and easy to read. With block-based success and failure handlers, you don't need to implement delegate protocols or provide selectors for callbacks.
  • AFNetworking and Grand Central Dispatch take care of threading for you, so your code does not need to manage threads, run selectors in the background, or invoke dispatch_async. Your completion blocks will be executed on the main thread (unless you configure the operations otherwise).
  • You can provide a better user experience while waiting for a response. Networks are unreliable, particularly for mobile users, and servers can be bogged down. Your users' experiences will be better if you design for a slow connection, which you can only do asynchronously.

However, in some cases, a synchronous response is better, such as when the document architecture or another framework is handling the multithreading for you, and expects a synchronous result. This code attempts to provide a safe and reliable way to use the framework synchronously.

While it overrides the default success and failure queues to avoid a deadlock, it can't anticipate every possible situation. In particular, you should not set the queue from which you're invoking as the processing queue, which will cause a deadlock.

The main thread

You shouldn't call these methods from the main thread. On iOS, if your application enters the background while one of these methods is running on the main thread, a deadlock may result and your application could be terminated.

AFImageRequestOperation processingBlock and custom operation subclasses

This category is suitable for most of the request operation subclasses built into AFNetworking, which process their response objects synchronously.

If you're using the processingBlock on AFImageRequestOperation, which contains essential processing in the completion handler, or your subclass performs other asynchronous processing in the completion handler, use the version in the using-completion-blocks branch.

All custom subclasses must override -responseObject. See AFHTTPRequestOperation+ResponseObject.h for more information.

Development

This project includes integration tests which use the delightful service httpbin. To run them, run pod install inside the TestProject folder, then load the workspace and execute the test action.

Acknowledgements

License

This project is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].