CTCellularPlanProvisioning, CTCellularPlanProvisioningAddPlanResultUnknown before the wizard finished

I'm using the below code to activate Esim,

 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];
            }];

When I call the method, it will simultaneously open the "Add Cellular Plan" wizard and return the CTCellularPlanProvisioningAddPlanResultUnknown. However, in the end, the Esim will add successfully, but I will not receive the prosperous state in "completion handler."

I found the solution

you need to move

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

at class level


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);
    }
}

CTCellularPlanProvisioning, CTCellularPlanProvisioningAddPlanResultUnknown before the wizard finished
 
 
Q