You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-8Lines changed: 27 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,16 @@ It works with `NSURLConnection`, `AFNetworking`, or any networking framework you
13
13
*[How it works](#how-it-works)
14
14
*[Documentation](#documentation)
15
15
*[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)
20
20
*[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)
25
26
*[Installing in your projects](#installing-in-your-projects)
26
27
*[About OHHTTPStubs Unit Tests](#about-ohhttpstubs-unit-tests)
27
28
*[Change Log](#change-log)
@@ -182,6 +183,24 @@ You can also setup a block to execute each time a request has been stubbed, usin
182
183
NSLog(@"%@ stubbed %@", request.URL, stub.name);
183
184
}];
184
185
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._
0 commit comments