1

I need to check, is esim installed in iphone. Using react-native for creating app. Found react-native-carrier-info which uses CTTelephonyNetworkInfo and CTCarrier

Can CTTelephonyNetworkInfo and CTCarrier show if esim installed or some info about this to make such conclusion? On simulator I could not see any info

Read coretelephony But I am not sure, is there native api for this task or which api can help me to make such conclusion

Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
teacake
  • 390
  • 4
  • 15

3 Answers3

3

In Swift, if you want to check eSim connectivity only, you can :

  // 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
      }
    }
  }

You can reinforce checking by using the new supportsCellularPlan() method on CTCellularPlanProvisioning.

jc_35
  • 1,073
  • 1
  • 9
  • 15
1

I hope that is to help you:

Basically do you need to create a Library to access the native library in Objective-C:

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

And into a new Library do you implement your access a native library:

#import <React/RCTBridgeModule.h>

@interface NetworkInfo : NSObject <RCTBridgeModule>
@end

Implementation:

// 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

And in your Javascript:

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

....your code

For further information:native-modules-ios

Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
  • Thanks for answer. What Is NetworkInfo api? I could not find it on https://developer.apple.com/documentation?changes=latest_minor And NetworkInfo - will provide me any info about esim ? – teacake Apr 25 '19 at 08:42
  • The NetworkInfo was the name that I put for example, do you put the name that you to want. The class created in this example to able access the native library´s objective c and you can get information the eSim through the library describe here https://developer.apple.com/documentation/coretelephony and to the solution to your request look here https://stackoverflow.com/questions/13644502/detect-if-sim-card-is-available-in-iphone-programmatically – Luciano Nascimento Apr 25 '19 at 12:46
  • Oh I see. But the main question is - which native api can help me to get info about esim ( installed or not or may be help me to make such conclusion). and seems CTTelephonyNetworkInfo and CTCarrier do not help me with my problem according to https://stackoverflow.com/a/55520052/9136852 – teacake Apr 25 '19 at 14:07
  • 1
    So, I try to create a example to you when I arrive in my home, at the moment I´m in my work. Sorry not to help you right now. :( – Luciano Nascimento Apr 25 '19 at 15:12
  • 1
    Hello! I implement a example and put it on git https://github.com/lucklpn/SimCardInfo I used the example that I found in this site https://www.npmjs.com/package/react-native-carrier-info I did find easier to implement this. I hope to help you! ;) – Luciano Nascimento Apr 27 '19 at 02:06
  • Thank you for helping. I will test this in few days – teacake Apr 29 '19 at 09:07
0

Make it simple!

Supports iOS 12+, Make sure to test it on eSim supported devices.

import CoreTelephony

func eSimSupported() -> Bool {
    let telephonyInfo = CTTelephonyNetworkInfo()
    guard let radioTechnologies =
            telephonyInfo.serviceCurrentRadioAccessTechnology,
          !radioTechnologies.isEmpty else {
        return false
    }
    return true
}

print("eSimSupported = \(eSimSupported())")
Yano
  • 585
  • 3
  • 18