From e05d8f3b15df2f98fbfba7b9937e0a4ecd4d0a77 Mon Sep 17 00:00:00 2001 From: Kelly Campbell Date: Wed, 19 Feb 2020 05:16:45 -0500 Subject: [PATCH] Return error if isProtectedDataAvailable = false Addresses issue #72 where SecItemCOpyMatching doesn't return data and doesn't give an error when the protected files are not yet available. This will now give an error instead of empty results, allowing the caller to retry after some delay. --- ios/RNSensitiveInfo/RNSensitiveInfo.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ios/RNSensitiveInfo/RNSensitiveInfo.m b/ios/RNSensitiveInfo/RNSensitiveInfo.m index 0c77b7c0..b3361046 100644 --- a/ios/RNSensitiveInfo/RNSensitiveInfo.m +++ b/ios/RNSensitiveInfo/RNSensitiveInfo.m @@ -215,7 +215,15 @@ - (NSString *)messageForError:(NSError *)error return; } - [self getItemWithQuery:query resolver:resolve rejecter:reject]; + dispatch_async(dispatch_get_main_queue(), ^{ + if (UIApplication.sharedApplication.protectedDataAvailable) { + [self getItemWithQuery:query resolver:resolve rejecter:reject]; + } else { + // TODO: could change to instead of erroring out, listen for protectedDataDidBecomeAvailable and call getItemWIthQuery when it does + // Experiment for now by returning an error and let the js side retry + reject(@"protected_data_unavailable", @"Protected data not available yet. Retry operation", nil); + } + }); } - (void)getItemWithQuery:(NSDictionary *)query resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {