From 7c2f04ef63c7a89e551bc33f1aa71262612556c2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 12 Apr 2023 02:38:00 +0300 Subject: [PATCH] iOS. getIcloudDocument(). Recursion is limited to 60s --- ios/RNCloudFs.m | 15 ++++++++++++++- types.d.ts | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ios/RNCloudFs.m b/ios/RNCloudFs.m index 9a95b11..ffd1548 100644 --- a/ios/RNCloudFs.m +++ b/ios/RNCloudFs.m @@ -173,6 +173,19 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_METHOD(getIcloudDocument:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter) { + [self getIcloudDocumentRecurse:options resolver:resolver rejecter:rejecter retryCount:1]; +} + +- (void)getIcloudDocumentRecurse:(NSDictionary *)options +resolver:(RCTPromiseResolveBlock)resolver +rejecter:(RCTPromiseRejectBlock)rejecter +retryCount:(int)retryCount { + if (retryCount > 30) { + NSString *errMsg = @"Failed to read document in 60 seconds"; + RCTLogTrace(errMsg); + return rejecter(@"error", errMsg, nil); + } + NSString *destinationPath = [options objectForKey:@"targetPath"]; NSString *scope = [options objectForKey:@"scope"]; @@ -218,7 +231,7 @@ - (dispatch_queue_t)methodQueue // Call itself until the file is ready RCTLogTrace(@"Waiting async 2s before retrying..."); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self getIcloudDocument:options resolver:resolver rejecter:rejecter]; + [self getIcloudDocumentRecurse:options resolver:resolver rejecter:rejecter retryCount:retryCount+1]; }); } } diff --git a/types.d.ts b/types.d.ts index 7a0c27e..7dad741 100644 --- a/types.d.ts +++ b/types.d.ts @@ -23,7 +23,7 @@ export interface TargetPathAndScope { targetPath: string; } -declare const defaultExport: { +declare const defaultExport: Readonly<{ /** iOS only */ isAvailable: () => Promise; @@ -93,6 +93,6 @@ declare const defaultExport: { /** iOS only */ getIcloudDocument: (options: TargetPathAndScope) => Promise; -}; +}>; export default defaultExport;