Skip to content

Commit 95ce0d3

Browse files
committed
Updated README
1 parent ab743d1 commit 95ce0d3

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

OHHTTPStubs/NSURLSessionConfiguration+OHHTTPStubs.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
#if 1
1211
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000)
1312

1413
#import <objc/runtime.h>
@@ -80,4 +79,3 @@ + (void)load
8079
@end
8180

8281
#endif
83-
#endif

README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ It works with `NSURLConnection`, `AFNetworking`, or any networking framework you
1313
* [How it works](#how-it-works)
1414
* [Documentation](#documentation)
1515
* [Usage examples](#usage-examples)
16-
* [Stub all requests with some given NSData](#stub-all-requests-with-some-given-nsdata)
17-
* [Stub only requests to your WebService](#stub-only-requests-to-your-webservice)
18-
* [Set request and response time](#set-request-and-response-time)
19-
* [Simulate a down network](#simulate-a-down-network)
16+
* [Stub all requests with some given NSData](#stub-all-requests-with-some-given-nsdata)
17+
* [Stub only requests to your WebService](#stub-only-requests-to-your-webservice)
18+
* [Set request and response time](#set-request-and-response-time)
19+
* [Simulate a down network](#simulate-a-down-network)
2020
* [Advanced Usage](#advanced-usage)
21-
* [Use macros to build your fixtures path](#use-macros-to-build-your-fixtures-path)
22-
* [Using download speed instead of responseTime](#using-download-speed-instead-of-responsetime)
23-
* [Stack multiple stubs and remove installed stubs](#stack-multiple-stubs-and-remove-installed-stubs)
24-
* [Name your stubs and log their activation](#name-your-stubs-and-log-their-activation)
21+
* [Use macros to build your fixtures path](#use-macros-to-build-your-fixtures-path)
22+
* [Using download speed instead of responseTime](#using-download-speed-instead-of-responsetime)
23+
* [Stack multiple stubs and remove installed stubs](#stack-multiple-stubs-and-remove-installed-stubs)
24+
* [Name your stubs and log their activation](#name-your-stubs-and-log-their-activation)
25+
* [OHHTTPStubs and NSURLSession](#ohhttpstubs-and-nsurlsession)
2526
* [Installing in your projects](#installing-in-your-projects)
2627
* [About OHHTTPStubs Unit Tests](#about-ohhttpstubs-unit-tests)
2728
* [Change Log](#change-log)
@@ -182,6 +183,24 @@ You can also setup a block to execute each time a request has been stubbed, usin
182183
NSLog(@"%@ stubbed %@", request.URL, stub.name);
183184
}];
184185

186+
### OHHTTPStubs and NSURLSession
187+
188+
`OHHTTPStubs` use a custom private `NSURLProtocol` to intercept its requests.
189+
190+
`OHHTTPStubs` is automatically enabled by default, both for requests made using:
191+
192+
* `NSURLConnection` or `[NSURLSession sharedSession]` _(that are based on `[NSURLProtocol registerProtocol:]` to look for custom protocols for every requests)_, because this protocol is installed as soon as you use the `OHHTTPStubs` class _(installed in the `+initialize` method)_
193+
* a `NSURLSession` created using a `NSURLSessionConfiguration` and `[NSURLSession sessionWithConfiguration:]` _(thanks to method swizzling that insert the private protocol used by `OHHTTPStubs` into the `protocolClasses` of `[NSURLSessionConfiguration defaultSessionConfiguration]` and `[NSURLSessionConfiguration ephemeralSessionConfiguration] automagically)_
194+
195+
> Note however that `OHHTTPStubs` **can't work on background sessions** (sessions created using `[NSURLSessionConfiguration backgroundSessionConfiguration]`) because background sessions don't allow the use of custom `NSURLProtocols`. There's nothing we can do about it, sorry.
196+
197+
If you need to disable (and re-enable) `OHHTTPStubs` globally or per session, you can use:
198+
199+
* `[OHHTTPStubs setEnabled:]` for `NSURLConnection`/`[NSURLSession sharedSession]`-based requests
200+
* `[OHHTTPStubs setEnabled:forSessionConfiguration:]` for requests sent on a session created using `[NSURLSession sessionWithConfiguration:...]`
201+
202+
_There is generally no need to explicitly call `setEnabled:` or `setEnabled:forSessionConfiguration:` using `YES` as this is the default._
203+
185204
----
186205

187206
## Installing in your projects

0 commit comments

Comments
 (0)