odemolliens / react-native-sim-cards-manager

React Native plugin to manage Sim card(s) & eSim
MIT License
67 stars 29 forks source link

The setupEsim function doesn't distinguish success from cancellation #65

Closed Uriah-Eisenstein-ATT closed 7 months ago

Uriah-Eisenstein-ATT commented 8 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-sim-cards-manager@1.0.18 for the project I'm working on.

The setupEsim function doesn't distinguish a success result from cancellation, at least on iOS (I think also on Android, but I'm not an Android developer so I'm not sure the flow is the same). Since the function returns a boolean in case of no error, I've patched it to return true only on success, and return false if the user cancels.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-sim-cards-manager/ios/SimCardsManager.m b/node_modules/react-native-sim-cards-manager/ios/SimCardsManager.m
index ffcb291..4f9b794 100644
--- a/node_modules/react-native-sim-cards-manager/ios/SimCardsManager.m
+++ b/node_modules/react-native-sim-cards-manager/ios/SimCardsManager.m
@@ -90,8 +90,8 @@ @implementation SimCardsManager
                     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));
+                    //CTCellularPlanProvisioningAddPlanResultSuccess or CTCellularPlanProvisioningAddPlanResultCancel
+                    resolve(@(result == CTCellularPlanProvisioningAddPlanResultSuccess));
                 }
                 [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
             }];

This issue body was partially generated by patch-package.

Regards, Uriah Eisenstein

odemolliens commented 7 months ago

Added to develop branch, thanks!