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

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

问题描述

好吧,我正在为Android和IOS平台开发一个应用程序,我正在从API中获取数据.我意识到我的应用无法在某些Android版本中获取数据.我在ororoid 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的android版本默认没有启用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中启用Tls 1.1和1.2(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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