Update the README
This commit is contained in:
Родитель
32c5236154
Коммит
17620901e1
47
README.md
47
README.md
|
@ -15,55 +15,14 @@ The good news is, you don't have to know either of these two libraries above,
|
|||
using ModernHttpClient is the most boring thing in the world. Here's how
|
||||
it works:
|
||||
|
||||
On iOS:
|
||||
|
||||
```cs
|
||||
var httpClient = new HttpClient(new NSUrlSessionHandler());
|
||||
```
|
||||
|
||||
On Android:
|
||||
|
||||
```cs
|
||||
var httpClient = new HttpClient(new OkHttpNetworkHandler());
|
||||
var httpClient = new HttpClient(new NativeMessageHandler());
|
||||
```
|
||||
|
||||
## How can I use this in a PCL?
|
||||
|
||||
Using ModernHttpClient from a PCL is fairly easy with some rigging, especially
|
||||
if you've got some sort of IoC/DI setup - request an HttpClient in your PCL,
|
||||
and register it in your app. However, here's what you can do without any
|
||||
external dependencies:
|
||||
|
||||
```cs
|
||||
// In your PCL
|
||||
public static class HttpClientFactory
|
||||
{
|
||||
public static Func<HttpClient> Get { get; set; }
|
||||
|
||||
static HttpClientFactory()
|
||||
{
|
||||
Get = (() => new HttpClient());
|
||||
}
|
||||
}
|
||||
|
||||
// Somewhere else in your PCL
|
||||
var client = HttpClientFactory.Get();
|
||||
|
||||
// In your iOS app (i.e. the startup of your app)
|
||||
public static class AppDelegate
|
||||
{
|
||||
public void FinishedLaunching(UIApplication app, NSDictionary options)
|
||||
{
|
||||
HttpClientFactory.Get = (() => new HttpClient(new NSUrlSessionHandler()));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## How can I use this in MvvmCross?
|
||||
|
||||
Check out Michael Ridland's blog post, [Implementing ModernHttpClient in
|
||||
MvvmCross](http://www.michaelridland.com/mobile/implementing-modernhttpclient-in-mvvmcross/),
|
||||
for more information.
|
||||
Just reference the Portable version of ModernHttpClient in your Portable
|
||||
Library, and it will use the correct version on all platforms.
|
||||
|
||||
## Building
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче