Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTCellularPlanProvisioningAddPlanResultUnknown #3

Open
sampertelus opened this issue Oct 28, 2022 · 1 comment
Open

CTCellularPlanProvisioningAddPlanResultUnknown #3

sampertelus opened this issue Oct 28, 2022 · 1 comment

Comments

@sampertelus
Copy link

sampertelus commented Oct 28, 2022

Can you find any solution for
Currently (iOS 14.2), there might be a bug in iOS SDK that returns unknown results before eSIM setup completion. More about it here

I'm having the same issue with IOS 15

@sampertelus
Copy link
Author

I found the solution you need to move

API_AVAILABLE(ios(12.0))
CTCellularPlanProvisioning *plan;
API_AVAILABLE(ios(12.0))
CTCellularPlanProvisioningRequest *request;

before the function declaration


API_AVAILABLE(ios(12.0))
CTCellularPlanProvisioning *plan;
API_AVAILABLE(ios(12.0))
CTCellularPlanProvisioningRequest *request;

RCT_EXPORT_METHOD(setupEsim:(NSDictionary *)config
                  promiseWithResolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
    
    if (@available(iOS 12.0, *)) {
        plan = [[CTCellularPlanProvisioning alloc] init];
        
        if (plan.supportsCellularPlan == NO) {
            NSError *error = [NSError errorWithDomain:@"react.native.simcardsmanager.handler" code:2 userInfo:nil];
            reject(@"1", @"The device doesn't support a cellular plan", error);
        } else {
            NSArray *arrayOfComponents = [config[@"confirmationCode"] componentsSeparatedByString:@"$"];
            request = [[CTCellularPlanProvisioningRequest alloc] init];
            request.OID = config[@"oid"];
            request.EID = config[@"eid"];
            request.ICCID = config[@"iccid"];
            request.address = arrayOfComponents[1];
            request.matchingID = arrayOfComponents[2];
            request.confirmationCode = config[@"confirmationCode"];
            
            UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}];
            
            [plan addPlanWith:request completionHandler:^(CTCellularPlanProvisioningAddPlanResult result) {
                if (result==CTCellularPlanProvisioningAddPlanResultFail){
                    NSError *error = [NSError errorWithDomain:@"react.native.simcardsmanager.handler" code:1 userInfo:nil];
                    reject(@"2", @"CTCellularPlanProvisioningAddPlanResultFail -  Can't add an Esim subscription", error);
                }else if (result==CTCellularPlanProvisioningAddPlanResultUnknown){
                    NSError *error = [NSError errorWithDomain:@"react.native.simcardsmanager.handler" code:1 userInfo:nil];
                    reject(@"3", @"CTCellularPlanProvisioningAddPlanResultUnknown - Can't setup eSim due to unknown error", error);
                }else{
                    //CTCellularPlanProvisioningAddPlanResultSuccess
                    resolve(@(true));
                }
                [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
            }];
        }
        
    } else {
        NSError *error = [NSError errorWithDomain:@"react.native.simcardsmanager.handler" code:1 userInfo:nil];
        reject(@"0", @"This functionality is not supported before iOS 12.0", error);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant