Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 1ed9cf5

Browse files
committed
Add #162 IOS implementation
1 parent 544784e commit 1ed9cf5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ - (NSDictionary *)constantsToExport
470470
}
471471
})
472472

473+
RCT_EXPORT_METHOD(df:(RCTResponseSenderBlock)callback
474+
{
475+
[RNFetchBlobFS df:callback];
476+
})
477+
473478
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
474479
UIWindow *window = [UIApplication sharedApplication].keyWindow;
475480
return window.rootViewController;

src/ios/RNFetchBlobFS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
//+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
6767
+ (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
6868
+ (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
69+
+ (void) df:(RCTResponseSenderBlock)callback;
6970

7071
// constructor
7172
- (id) init;

src/ios/RNFetchBlobFS.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,31 @@ + (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * pa
722722
}
723723
}
724724

725+
#pragma mark - get disk space
726+
727+
+(void) df:(RCTResponseSenderBlock)callback
728+
{
729+
uint64_t totalSpace = 0;
730+
uint64_t totalFreeSpace = 0;
731+
NSError *error = nil;
732+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
733+
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
734+
735+
if (dictionary) {
736+
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
737+
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
738+
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
739+
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
740+
callback(@[[NSNull null], @{
741+
@"free" : [NSNumber numberWithInt:totalFreeSpace],
742+
@"total" : [NSNumber numberWithInt:totalSpace]
743+
}]);
744+
} else {
745+
callback(@[@"failed to get storage usage."]);
746+
}
747+
748+
}
749+
725750
+ (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest
726751
{
727752
int read = 0;

0 commit comments

Comments
 (0)