如何在 react native (android) 中启用 Tls 1.1 和 1.2 [英] How enable Tls 1.1 and 1.2 in react native (android)

查看:36
本文介绍了如何在 react native (android) 中启用 Tls 1.1 和 1.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我正在为 android 和 IOS 平台开发一个应用程序,在我的应用程序中,我正在从 API 中提取数据.我意识到我的应用无法在某些 android 版本中获取数据.我在 andoroid 4.1、4.4 和 5.1 中进行了测试.这些版本不影响数据.但是Android 7,fetch我没有问题.

Well, I'm developing an app for android and IOS platform, inside my app I'm fecthing data from an API. I realised that my app can't fetch data in some android versions. I tested in andoroid 4.1, 4.4 and 5.1. These versions do not fecth data. But Android 7, fetch and I do not have problems.

我一直在寻找解决方案,我发现使用 minSdkVersion 16 的 androids 版本默认没有启用 TLS 1.1 和 1.2.(这是从 20 sdkVersion 实现的)为了启用它们,我将不得不使用 Java.3 个月前我刚刚使用 react-native,而且我不是 Java 程序员.所以我看到的东西,不要告诉我我必须做什么.谁能告诉我在 react-native android 应用程序中启用 TLS 1.1 和 TLS 2.2 的步骤.我只看到给出要添加的代码的示例,它们没有解释或说明步骤.我还阅读了一条评论,说启用 TLS 1.1 和 1.2 后,应用程序无法上传到 Play 商店.

I was looking for the solution, I found that androids versions using minSdkVersion 16, they do not have TLS 1.1 and 1.2 enable by default. (This is implemented from 20 sdkVersion) And to enable them, I will have to do with Java. I'm just working with react-native 3 months ago and I'm not a java programmer. So the stuffs i'm seeing around, do not tell me exactly what I'll have to do. Can any one tell me steps to enable TLS 1.1 and TLS 2.2 in a react-native android app. I just see exemples that give the code to add, they do not explain or tell the steps. And I also read a comment that says by enabling the TLS 1.1 and 1.2 the app can't be uploaded in play store.

推荐答案

在android中添加这个库build.gradle

add this library in android build.gradle

implementation 'com.google.android.gms:play-services-safetynet:+'

并将此代码添加到您的 MainApplication.java

and add this code to your MainApplication.java

import android.content.Intent;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.security.ProviderInstaller;
import com.google.android.gms.security.ProviderInstaller.ProviderInstallListener;

@Override
  public void onCreate() {
    super.onCreate();
    upgradeSecurityProvider();
    SoLoader.init(this, /* native exopackage */ false);
  }

  private void upgradeSecurityProvider() {
    ProviderInstaller.installIfNeededAsync(this, new ProviderInstallListener() {
      @Override
      public void onProviderInstalled() {

      }

      @Override
      public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
//        GooglePlayServicesUtil.showErrorNotification(errorCode, MainApplication.this);
        GoogleApiAvailability.getInstance().showErrorNotification(MainApplication.this, errorCode);
      }
    });
  }

这篇关于如何在 react native (android) 中启用 Tls 1.1 和 1.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆