@@ -82,9 +82,13 @@ - (BOOL)updateKeychainValue:(NSString *)password forIdentifier:(NSString *)ident
8282 return NO ;
8383}
8484
85- - (void )deleteKeychainValue : (NSString *)identifier {
85+ - (BOOL )deleteKeychainValue : (NSString *)identifier {
8686 NSMutableDictionary *searchDictionary = [self newSearchDictionary: identifier];
87- SecItemDelete ((CFDictionaryRef)searchDictionary);
87+ OSStatus status = SecItemDelete ((CFDictionaryRef)searchDictionary);
88+ if (status == errSecSuccess) {
89+ return YES ;
90+ }
91+ return NO ;
8892}
8993
9094- (void )clearSecureKeyStore
@@ -111,7 +115,7 @@ - (void)handleAppUninstallation
111115
112116NSError * secureKeyStoreError (NSString *errMsg)
113117{
114- NSError *error = [NSError errorWithDomain: serviceName code: 200 userInfo: @{@" Error reason" : errMsg}];
118+ NSError *error = [NSError errorWithDomain: serviceName code: 200 userInfo: @{@" reason" : errMsg}];
115119 return error;
116120}
117121
@@ -129,12 +133,14 @@ - (void)handleAppUninstallation
129133 if (status) {
130134 resolve (@" key updated successfully" );
131135 } else {
132- reject (@" no_events" , @" Not able to save key" , secureKeyStoreError (@" Not able to save key" ));
136+ NSString * errorMessage = @" {\" message\" :\" error saving key\" }" ;
137+ reject (@" 9" , errorMessage, secureKeyStoreError (errorMessage));
133138 }
134139 }
135140 }
136141 @catch (NSException *exception) {
137- reject (@" no_events" , @" Not able to save key" , secureKeyStoreError (exception.reason ));
142+ NSString * errorMessage = [NSString stringWithFormat: @" {\" message\" :\" error saving key, please try to un-install and re-install app again\" ,\" actual-error\" :%@ }" , exception];
143+ reject (@" 9" , errorMessage, secureKeyStoreError (errorMessage));
138144 }
139145}
140146
@@ -146,13 +152,15 @@ - (void)handleAppUninstallation
146152 [self handleAppUninstallation ];
147153 NSString *value = [self searchKeychainCopyMatching: key];
148154 if (value == nil ) {
149- reject (@" no_events" , @" Not able to find key" , secureKeyStoreError (@" Not able to find key" ));
155+ NSString * errorMessage = @" {\" message\" :\" key does not present\" }" ;
156+ reject (@" 1" , errorMessage, secureKeyStoreError (errorMessage));
150157 } else {
151158 resolve (value);
152159 }
153160 }
154161 @catch (NSException *exception) {
155- reject (@" no_events" , @" Not able to find key" , secureKeyStoreError (exception.reason ));
162+ NSString * errorMessage = [NSString stringWithFormat: @" {\" message\" :\" key does not present\" ,\" actual-error\" :%@ }" , exception];
163+ reject (@" 1" , errorMessage, secureKeyStoreError (errorMessage));
156164 }
157165}
158166
@@ -161,11 +169,17 @@ - (void)handleAppUninstallation
161169 rejecter:(RCTPromiseRejectBlock)reject)
162170{
163171 @try {
164- [self deleteKeychainValue: key];
165- resolve (@" key removed successfully" );
172+ BOOL status = [self deleteKeychainValue: key];
173+ if (status) {
174+ resolve (@" key removed successfully" );
175+ } else {
176+ NSString * errorMessage = @" {\" message\" :\" could not delete key\" }" ;
177+ reject (@" 6" , errorMessage, secureKeyStoreError (errorMessage));
178+ }
166179 }
167180 @catch (NSException *exception) {
168- reject (@" no_events" , @" Could not remove key from keychain" , secureKeyStoreError (exception.reason ));
181+ NSString * errorMessage = [NSString stringWithFormat: @" {\" message\" :\" could not delete key\" ,\" actual-error\" :%@ }" , exception];
182+ reject (@" 6" , errorMessage, secureKeyStoreError (errorMessage));
169183 }
170184}
171185
0 commit comments