Skip to content

Commit

Permalink
iOS. getIcloudDocument(). Recursion is limited to 60s
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tsx committed Apr 11, 2023
1 parent 1e87c46 commit e425152
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion ios/RNCloudFs.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down Expand Up @@ -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];
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.6.0",
"description": "",
"main": "index.js",
"types": "types.d.ts",
"typings": "types.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down

0 comments on commit e425152

Please sign in to comment.