zoukankan      html  css  js  c++  java
  • 【react-native】--------------检测SIM卡是否安装-------------【劉】

    在react-naitve检测手机是否安装SIM卡

    1、Android检测

      import android.telephony.TelephonyManager;
        /**
          * 判断是否包含SIM卡
          *
          * @return 状态
          */
      public static boolean hasSimCard(Context context) {
        TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telMgr.getSimState();
        boolean result = true;
        switch (simState) {
        case TelephonyManager.SIM_STATE_ABSENT:
          result = false; // 没有SIM卡
          break;
        case TelephonyManager.SIM_STATE_UNKNOWN:
          result = false;
          break;
        }
        Log.e("try", result ? "有SIM卡" : "无SIM卡");
        return result;
      }

    2、IOS检测

      RCT_EXPORT_METHOD(isSIMInstalled:(RCTResponseSenderBlock)complete){
        CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
    
        CTCarrier *carrier = [networkInfo subscriberCellularProvider];
         
        if (!carrier.isoCountryCode) {
            NSLog(@"未安装SIM卡");
          }else{
            NSLog(@"存在SIM卡");
          }
    }

      

  • 相关阅读:
    反射 元类
    多态
    封装
    继承
    面向基础
    包 logging模块 hashlib模块 openpyxl 深浅拷贝
    常用模块
    re模块(正则表达式)
    模块 导入方式 软件开发目录规范
    第 3 章 镜像
  • 原文地址:https://www.cnblogs.com/lstcon/p/11953345.html
Copyright © 2011-2022 走看看