Automatically sets the network activity indicator for any performed request.
BIG BROTHER IS WATCHING YOU.
BigBrother is a Swift library made for iOS that automatically watches for any performed request and sets the network activity indicator.
This is mostly a proof of concept, having several limitations because of how
NSURLProtocolworks. Some of them are:
NSURLProtocoldoesn't inherit
NSURLSession's configured headers (see https://github.com/Alamofire/Alamofire/issues/473)
NSURLProtocolisn't compatible with authentication APIs (see https://github.com/marcelofabri/BigBrother/issues/2)
It was inspired by this comment by Mattt Thompson.
It also was based on this tutorial for creating an
NSURLProtocoland on
AFNetworkActivityIndicatorManagerfrom AFNetworking.
NSURLConnectionand
NSURLSession.sharedSession()
BigBrother.addToSharedSession()
NSURLSessionConfiguration
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()BigBrother.addToSessionConfiguration(configuration)
let session = NSURLSession(configuration: configuration)
NSURLConnectionand
NSURLSession.sharedSession()
BigBrother.removeFromSharedSession()
NSURLSessionConfiguration
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()BigBrother.removeFromSessionConfiguration(configuration)
let newSession = NSURLSession(configuration: configuration)
It is important to configure your NSURLSessionConfiguration object appropriately before using it to initialize a session object. Session objects make a copy of the configuration settings you provide and use those settings to configure the session. Once configured, the session object ignores any changes you make to the NSURLSessionConfiguration object. If you need to modify your transfer policies, you must update the session configuration object and use it to create a new NSURLSession object.
BigBrother.URLProtocolis an
NSURLProtocolsubclass that manages the network activity indicator and it's public if you want to add it yourself to an
NSURLSessionConfigurationor to the default
NSURLProtocol(used by
NSURLConnectionand
NSURLSession.sharedSession()).
BigBrother.Manageris also public, so you can manage the network activity indicator directly:
BigBrother.Manager.sharedInstance.incrementActivityCount()// do something...
BigBrother.Manager.sharedInstance.decrementActivityCount()
BigBrother is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BigBrother'
Then run
pod installwith CocoaPods 0.36 or newer.
Unit testing is done with
XCTestand the tests are available under the BigBrotherTests folder.
Marcelo Fabri
BigBrother is available under the MIT license. See the LICENSE file for more info.