We are trying to let a button open the native eSim flow.
We got pretty far with the "react-native-sim-cards-manager", but we got stuck on the ios with error messages:
CTCellularPlanProvisioningAddPlanResultUnknown - Can't setup eSim due to unknown error
So far we figured out that this is because there are 2 different flows to active a eSim:
- Making a carrier app
- Making LPA app
We do also generate a QR code for activating eSim where we use this string:
LPA:1$${smdp_address}$${activation_code}$$1
And this works great.
So now we are trying to find a way to just open this same link but then behind a button inside the app with something like Linking.openURL()
We are also trying to create out custom module:
#import "RCTEsimModule.h"
@import CoreTelephony;
#import <Foundation/Foundation.h>
#import <React/RCTLog.h>
@implementation RCTEsimModule
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(activate:(NSString *)address
activationCode:(NSString *)activationCode
promiseWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
if (@available(iOS 12.0, *)) {
CTCellularPlanProvisioning *plan = [[CTCellularPlanProvisioning alloc] init];
if (plan.supportsCellularPlan != YES) {
NSError *error = [NSError errorWithDomain:@"react.native.esim.native.module" code:2 userInfo:nil];
reject(@"Doesn't support cellular plan", @"This functionality is not supported on this device", error);
} else {
CTCellularPlanProvisioningRequest *request = [[CTCellularPlanProvisioningRequest alloc] init];
NSString *addressLPA = [NSString stringWithFormat:@"LPA:1$%@$%@", address, activationCode];
RCTLogInfo(addressLPA);
request.address = addressLPA; // LPA:1$XXXXXXXXXXXXXXXXX
// The user may send your app to the background prior to finishing the eSIM installation. To ensure your app has an opportunity to execute the completion handler and get the installation result, perform the eSIM installation as a background task. To do so, call beginBackgroundTask(expirationHandler:) prior to calling addPlan(with:completionHandler:), then call endBackgroundTask(_:) inside the completion handler.
UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}];
[plan addPlanWith:request completionHandler:^(CTCellularPlanProvisioningAddPlanResult result) {
resolve(@(result));
[[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
}];
}
} else {
NSError *error = [NSError errorWithDomain:@"react.native.esim.native.module" code:1 userInfo:nil];
reject(@"iOS 12 api availability", @"This functionality is not supported before iOS 12.0", error);
}
}
@end
But no luck yet. We are getting "Unable to activate eSIM".
Any advice would be appreciated! For context we use "Truphone" as a backend service.