how to use my own OkHttp client in react-native (0.54 + )

情到浓时终转凉″ 提交于 2019-12-04 10:38:36

I've not had a chance to test this out, but according to the discussion on [this issue][1], the following should work in 0.54+ to set a custom OkHttp client.

Create React Native application and set a custom factory in the constructor, e.g. OkHttpClientProvider.setOkHttpClientFactory(new CustomNetworkModule());

Where a custom factory would look like:

class CustomNetworkModule implements OkHttpClientFactory {
    public OkHttpClient createNewNetworkModuleClient() {
        return new OkHttpClient.Builder()
                        .cookieJar(new ReactCookieJarContainer())
                        .build();
    }
}

The above is based on info from this commit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!