【问题标题】:Is there API for checking if eSIM is installed in iphone?是否有用于检查 iPhone 中是否安装了 eSIM 的 API?
【发布时间】:2019-04-24 15:04:18
【问题描述】:

我需要检查一下,esim 是否安装在 iphone 中。 使用react-native 创建应用程序。找到react-native-carrier-info 它使用CTTelephonyNetworkInfoCTCarrier

CTTelephonyNetworkInfoCTCarrier 是否可以显示是否安装了esim 或有关此的一些信息来得出这样的结论? 在模拟器上我看不到任何信息

阅读coretelephony 但我不确定,这个任务是否有本机 api,或者哪个 api 可以帮助我做出这样的结论

【问题讨论】:

    标签: ios swift iphone react-native


    【解决方案1】:

    在 Swift 中,如果您想检查 eSim 连接,您可以:

      // First, check if the currentRadioAccessTechnology is nil
      // It means that no physical Sim card is inserted
      let telephonyInfo = CTTelephonyNetworkInfo()
      if telephonyInfo.currentRadioAccessTechnology == nil {
        // Next, on iOS 12 only, you can check the number of services connected
        // With the new serviceCurrentRadioAccessTechnology property
        if #available(iOS 12, *) {
          if let radioTechnologies =
            telephonyInfo.serviceCurrentRadioAccessTechnology, !radioTechnologies.isEmpty {
            // One or more radio services has been detected,
            // the user has one (ore more) eSim package connected to a network
          }
        }
      }
    

    您可以在CTCellularPlanProvisioning 上使用新的supportsCellularPlan() 方法来加强检查。

    【讨论】:

      【解决方案2】:

      希望对你有帮助:

      基本上你需要创建一个Library来访问Objective-C中的原生库:

      1 - npm install -g react-native-create-library
      2 - react-native-create-library MyLibrary
      3 - npm install
      

      在一个新的库中,您是否实现了对本机库的访问:

      #import <React/RCTBridgeModule.h>
      
      @interface NetworkInfo : NSObject <RCTBridgeModule>
      @end
      

      实施:

      // NetworkInfo.m
      #import "NetworkInfo.h"
      #import <React/RCTLog.h>
      
      @implementation NetworkInfo
      
      // To export a module named NetworkInfo
      RCT_EXPORT_MODULE();
      
      RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location)
      {
        RCTLogInfo(@"Pretending to create an event %@ at %@", name, location);
      }
      
      @end
      

      在你的 Javascript 中:

      import {NativeModules} from 'react-native';
      var NetworkInfo = NativeModules.NetworkInfo;
      

      ....你的代码

      更多信息:native-modules-ios

      【讨论】:

      猜你喜欢
      • 2011-10-14
      • 1970-01-01
      • 2021-11-23
      • 2017-04-13
      • 2012-03-28
      • 1970-01-01
      • 2013-03-23
      • 2010-11-06
      • 2020-10-18
      相关资源
      最近更新 更多