是否有API检查iSIM是否已安装在iPhone中?

时间:2019-04-24 15:04:18

标签: ios swift iphone react-native

我需要检查esim中是否安装了iphone。 使用react-native创建应用。找到react-native-carrier-info 使用CTTelephonyNetworkInfoCTCarrier

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

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

2 个答案:

答案 0 :(得分:2)

希望对您有所帮助

基本上,您需要创建一个库来访问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

答案 1 :(得分: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
      }
    }
  }

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