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/package.json b/package.json index 66ee88f..bbbc484 100644 --- a/package.json +++ b/package.json @@ -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" },