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 7c2f04e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 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
4 changes: 2 additions & 2 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface TargetPathAndScope {
targetPath: string;
}

declare const defaultExport: {
declare const defaultExport: Readonly<{
/** iOS only */
isAvailable: () => Promise<boolean>;

Expand Down Expand Up @@ -93,6 +93,6 @@ declare const defaultExport: {

/** iOS only */
getIcloudDocument: (options: TargetPathAndScope) => Promise<string | undefined>;
};
}>;

export default defaultExport;

0 comments on commit 7c2f04e

Please sign in to comment.