SWNetworking alternatives and similar libraries
Based on the "Networking" category.
Alternatively, view SWNetworking alternatives based on common mentions on social networks and blogs.
-
AFNetworking
A delightful networking framework for iOS, macOS, watchOS, and tvOS. -
CocoaAsyncSocket
Asynchronous socket networking library for Mac and iOS -
RestKit
RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X -
YTKNetwork
YTKNetwork is a high level request util based on AFNetworking. -
ASIHTTPRequest
Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone -
Reachability.swift
Replacement for Apple's Reachability re-written in Swift with closures -
swift-protobuf
Plugin and runtime library for using protobuf with Swift -
apollo-ios
📱 A strongly-typed, caching GraphQL client for iOS, written in Swift. -
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! 🦊 -
RealReachability
We need to observe the REAL reachability of network. That's what RealReachability do. -
MonkeyKing
MonkeyKing helps you to post messages to Chinese Social Networks. -
SwiftHTTP
Thin wrapper around NSURLSession in swift. Simplifies HTTP requests. -
Siesta
The civilized way to write REST API clients for iOS / macOS -
APIKit
Type-safe networking abstraction layer that associates request type with response type. -
ResponseDetective
Sherlock Holmes of the networking layer. :male_detective: -
Networking
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support -
XMNetworking
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking. -
Pitaya
🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines -
SPTDataLoader
The HTTP library used by the Spotify iOS client -
Reach
A simple class to check for internet connection availability in Swift. -
Digger
Digger is a lightweight download framework that requires only one line of code to complete the file download task -
SOAPEngine
This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app. -
TRON
Lightweight network abstraction layer, written on top of Alamofire -
TWRDownloadManager
A modern download manager based on NSURLSession to deal with asynchronous downloading, management and persistence of multiple files. -
Transporter
A tiny library makes uploading and downloading easier -
ws ☁️
⚠️ Deprecated - (in favour of Networking) :cloud: Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing) -
Restofire
Restofire is a protocol oriented networking client for Alamofire -
EVURLCache
a NSURLCache subclass for handling all web requests that use NSURLRequest -
AFNetworking+RetryPolicy
Nice category that adds the ability to set the retry interval, retry count and progressiveness. -
MultiPeer
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices -
AFNetworking-Synchronous
Synchronous requests for AFNetworking 1.x, 2.x, and 3.x -
ROADFramework
ROAD – Rapid Objective-C Applications Development
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of SWNetworking or a related project?
README
SWNetworking
SkyWite is an open-source and highly versatile multi-purpose frameworks. Clean code and sleek features make SkyWite an ideal choice. Powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use.
Achieve your deadlines by using SkyWite. You will save Hundred hours.
Start development using Skywite. Definitely you will be happy....! yeah..
Requirements
You need to add "SystemConfiguration" framework into your project before implement this.
How to apply to Xcode project
Downloading Source Code
- Download SWNetworking from gitHub
- Add required frameworks
- import "SWNetworking.h" to your source code file
Using CocoaPods
SWNetworking is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SWNetworking"
If you are new to CocoaPods, please go to Wiki page.
- Read the SWNetworking 1.0 Migration Guide for an overview of the architectural changes from 0.9.3
Communication
- If you need any help, use Stack Overflow. (Tag 'swnetworking') or you can send a mail with details ( we will provide fast feedback )
- If you'd like to ask a general question, use Stack Overflow.
- If you found a bug, and can provide steps to reliably reproduce it, open an issue or you can contribute.
- If you have a feature request, send a request mail we will add as soon as possible.
- If you want to contribute, submit a pull request.
Architecture
SWRequest
SWRequest
SWGETRequest
SWPOSTRequest
SWMultiPartRequest
SWPUTRequest
SWPATCHRequest
SWDELETERequest
SWHEADRequest
SWOfflineRequestManger
ResponseType
SWResponseDataType
SWResponseJSONDataType
SWResponseXMLDataType
SWResponseStringDataType
SWResponseUIImageType
SWRequestDataType
SWRequestFormData
SWRequestMulitFormData
SWRequestJSONData
Reachability
SWReachability
File
SWMedia
UIKit+SWNetworking
UIImageView+SWNetworking
UIProgressView+SWNetworking
# How to Use
Use HTTP Request will be NSURLSession
ALL Requests will be NSURLSession. Session will add in to NSOperationQueue
. Request creation , response serialization, network reachability handing and offline request as well.
GET
Request
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
[getRequest startDataTaskWithURL:@"http://127.0.0.1:3000" parameters:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
If you want send parameters you have two options
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.responseDataType = [SWResponseJSONDataType type];
[getRequest startDataTaskWithURL:@"http://127.0.0.1:3000" parameters:@"name=this is name&address=your address" parentView:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
If you want to encdoe parameters and values you need to pass NSDictionary
object with keys/values.
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.responseDataType = [SWResponseJSONDataType type];
[getRequest startDataTaskWithURL:@"http://127.0.0.1:3000" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
We are recommend to use second option because if you have &
sign with parameter or value it will break sending values.
GET
with Response type
Available as response types
SWResponseJSONDataType
, SWResponseJSONDataType
, SWResponseXMLDataType
,SWResponseStringDataType
,SWResponseUIImageType
You need set responseDataType
.
// this response will be JSON
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.responseDataType = [SWResponseJSONDataType type];
[getRequest startDataTaskWithURL:@"http://127.0.0.1:3000" parameters:nil parentView:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
GET
with loading indicator
If you set your parent view to method, loading indicator will be displayed.
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.responseDataType = [SWResponseJSONDataType type];
[getRequest startDataTaskWithURL:@"http://127.0.0.1:3000" parameters:nil parentView:self.view success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
If you want custom loading view you need to add new nib
file to your project and name it as 'sw_loadingView'. It will be displayed on the screen.
Cache Response
If you want to access cached data on the response. You need to use relevant method that include cache block
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.responseDataType = [SWResponseJSONDataType type];
[getRequest startDataTaskWithURL:@"http://127.0.0.1:3000" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
POST
request (simple)
Cache, Loading view available for the on the relevant method. Please check available methods
SWPOSTRequest *postRequest = [[SWPOSTRequest alloc]init];
postRequest.responseDataType = [SWResponseJSONDataType type];
[postRequest startDataTaskWithURL:@"http://127.0.0.1:3000/drivers" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];
POST
multipart request
It is really easy.
SWPOSTRequest *postRequest = [[SWPOSTRequest alloc]init];
postRequest.responseDataType = [SWResponseJSONDataType type];
//need to crate files array to upload
UIImage *image = [UIImage imageNamed:@"skywite"];
NSData *imageData = UIImagePNGRepresentation(image);
SWMedia *file1 = [[SWMedia alloc]initWithFileName:@"imagefile.png" key:@"image" data:imageData];
//create with custom mine type one
SWMedia *file2 = [[SWMedia alloc]initWithFileName:@"image.jpg" key:@"image2" mineType:@"image/jpeg" data:imageData];
//create an array with files
NSArray *fileArray = @[file1, file2];
[postRequest startUploadTaskWithURL:@"http://127.0.0.1:3000/drivers" files:fileArray parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil
cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionUploadTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];
PUT
simple request
SWPUTRequest *putRequest = [[SWPUTRequest alloc]init];
putRequest.responseDataType = [SWResponseXMLDataType type];
[putRequest startDataTaskWithURL:@"http://127.0.0.1:3000/drivers" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];}
PATCH
simple request
SWPATCHRequest *patchRequest = [[SWPATCHRequest alloc]init];
patchRequest.responseDataType = [SWResponseXMLDataType type];
[patchRequest startDataTaskWithURL:@"http://127.0.0.1:3000/drivers" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];
DELETE
simple request
SWDELETERequest *deleteRequest = [[SWDELETERequest alloc]init];
deleteRequest.responseDataType = [SWResponseXMLDataType type];
[deleteRequest startDataTaskWithURL:@"http://127.0.0.1:3000/drivers" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];
HEAD
simple request
SWHEADRequest *headRequest = [[SWHEADRequest alloc]init];
headRequest.responseDataType = [SWResponseXMLDataType type];
[headRequest startDataTaskWithURL:@"http://127.0.0.1:3000/drivers" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];}
Features
all the following features averrable on all the request types. eg : If you want to access you need to call relevant method that include cache block
Custom headers
If you want to add custom headers you can set to accessing request object.
SWPOSTRequest *postRequest = [[SWPOSTRequest alloc]init];
[postRequest.request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
postRequest.responseDataType = [SWResponseJSONDataType type];
[postRequest startDataTaskWithURL:@"your URL String" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:self.view cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
Custom time out
If you want to change request timeout , you have to change property call timeOut
.
SWPOSTRequest *postRequest = [[SWPOSTRequest alloc]init];
[postRequest setTimeOut:120];
postRequest.responseDataType = [SWResponseJSONDataType type];
[postRequest startDataTaskWithURL:@"your URL String" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:self.view cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
Response Encoding
You need to sent object type for the responseDataType
on all your requests.
//JSON
SWPOSTRequest *postRequest = [[SWPOSTRequest alloc]init];
postRequest.responseDataType = [SWResponseJSONDataType type];
[postRequest startDataTaskWithURL:@"your URL String" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:self.view cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
//XML
SWPOSTRequest *postRequestXML = [[SWPOSTRequest alloc]init];
postRequestXML.responseDataType = [SWResponseJSONDataType type];
[postRequestXML startDataTaskWithURL:@"your URL String" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:self.view cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
//String
SWPOSTRequest *postRequestString = [[SWPOSTRequest alloc]init];
postRequestString.responseDataType = [SWResponseStringDataType type];
[postRequestString startDataTaskWithURL:@"your URL String" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:self.view cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
//String
SWGETRequest *getRequestImage = [[SWGETRequest alloc]init];
getRequestImage.responseDataType = [SWResponseUIImageType type];
[getRequestImage startDataTaskWithURL:@"your URL String" parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:self.view cachedData:^(NSCachedURLResponse *response, id responseObject) {
NSLog(@"%@", responseObject);
} success:^(NSURLSessionDataTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
}];
UIImageView
with SWNetworking
No need to download image and set to UIImageView
anymore. You can set url to UIImageView
.
// Please use only one method . you can see 4 methods :)
// from url
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
[imageView loadWithURLString:@"image url"];
//if you want to load image cache and then load download you can use following method
[imageView loadWithURLString:@"image url" loadFromCacheFirst:YES];
//If you want to get complete event
[imageView loadWithURLString:@"image url" complete:^(UIImage *image) {
//you can assing your image to your object here.
}];
//if you want cache and image handle
[imageView loadWithURLString:@"image url" loadFromCacheFirst:YES complete:^(UIImage *image) {
}];
Check Reachability
New Reachability class to support block when change network status available Status
SWNetworkReachabilityStatusNotReachable
SWNetworkReachabilityStatusReachableViaWWAN
SWNetworkReachabilityStatusReachableViaWiFi
if ([SWReachability getCurrentNetworkStatus] == SWNetworkingReachabilityStatusNotReachable) {
//connection not available.
}
//if you want to get status change notification
[SWReachability checkCurrentStatus:^(SWNetworkingReachabilityStatus currentStatus) {
//current status when call method
} statusChange:^(SWNetworkingReachabilityStatus changedStatus) {
//every time when change status
}];
Upload progress With Request
SWPOSTRequest *postRequest = [[SWPOSTRequest alloc]init];
postRequest.responseDataType = [SWResponseJSONDataType type];
//need to crate files array to upload
UIImage *image = [UIImage imageNamed:@"skywite"];
NSData *imageData = UIImagePNGRepresentation(image);
SWMedia *file1 = [[SWMedia alloc]initWithFileName:@"imagefile.png" key:@"image" data:imageData];
//create with custom mine type one
SWMedia *file2 = [[SWMedia alloc]initWithFileName:@"image.jpg" key:@"image2" mineType:@"image/jpeg" data:imageData];
//create an array with files
NSArray *fileArray = @[file1, file2];
[postRequest startUploadTaskWithURL:@"http://127.0.0.1:3000/drivers" files:fileArray parameters:@{@"name": @"this is name", @"address": @"your address"} parentView:nil success:^(NSURLSessionUploadTask *uploadTask, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"%@", error);
}];
[postRequest setUploadProgressBlock:^(long long bytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"bytesWritten => %lld and totalBytesExpectedToWrite = %lld", bytesWritten, totalBytesExpectedToWrite);
}];
Download Progress With Request
SWGETRequest *getR = [[SWGETRequest alloc]init];
[getR startDownloadTaskWithURL:@"http://samples.mplayerhq.hu/A-codecs/ACELP.net/2001-04-11.asf" parameters:nil parentView:nil cachedData:^(NSCachedURLResponse *response, NSURL *location) {
} success:^(NSURLSessionDownloadTask *uploadTask, NSURL *location) {
NSLog(@"location %@", location);
} failure:^(NSURLSessionTask *uploadTask, NSError *error) {
NSLog(@"error %@", error);
}];
[getR setDownloadProgressBlock:^(long long bytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"bytesWritten => %lld and totalBytesExpectedToWrite = %lld", bytesWritten, totalBytesExpectedToWrite);
}];
Pass object to response block
You can set custom object to your request object as userObject
. This will allow any type
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.userObject = //any type object.
Identify the Request
You can set tag
for the request
SWGETRequest *getRequest = [[SWGETRequest alloc]init];
getRequest.tag = 12;
Offline request from SWNetworking
This is really simple. First of all you need to send offline request expire time. this is seconds
[SWOfflineRequestManger requestExpireTime:1300 ];
You have methods with parameter passing sendLaterIfOllfine
. Just pass YES
. That's it.
SWGETRequest *getR = [[SWGETRequest alloc]init];
getR.tag = 400;
[getR startDataTaskWithURL:@"http://www.google.com" parameters:nil parentView:nil sendLaterIfOffline:YES cachedData:^(NSCachedURLResponse *response, id responseObject) {
} success:^(NSURLSessionDataTask *operation, id responseObject) {
} failure:^(NSURLSessionTask *operation, NSError *error) {
}];
If you want catch offline request you need to use following methods. Better to add following lines to your AppDelegate
didFinishLaunchingWithOptions methods.
[[SWOfflineRequestManger sharedInstance] requestSuccessBlock:^(SWRequest *operation, id responseObject) {
NSLog(@"%d", operation.tag);
} requestFailBlock:^(SWRequest *operation, NSError *error) {
}];
Please note you need to set tag
or userObject
to identify the request. userObject
should be `'NSCording' support object
Set Task for UIProgressView
Please use following method to set task for UIProgressView
-(void)setDownloadTask:(NSURLSessionDownloadTask *)downloadTask;
-(void)setUploadTask:(NSURLSessionUploadTask *)downloadTask;
Credits
SWNetworking
is owned and maintained bye the SkyWite
SWNetworking
was originally created by saman kumara. If you want to contact [email protected]
Security disclosure
If you believe you have identified a security vulnerability with SWNetworking
, you should report it as soon as possible via email to [email protected]. Please do not post it to a public issue tracker.
License
SWNetworking
is released under the MIT license. See LICENSE for details.
*Note that all licence references and agreements mentioned in the SWNetworking README section above
are relevant to that project's source code only.