Browse Source

Add #162 IOS implementation

Ben Hsieh 8 years ago
parent
commit
1ed9cf5f26
3 changed files with 31 additions and 0 deletions
  1. 5
    0
      src/ios/RNFetchBlob/RNFetchBlob.m
  2. 1
    0
      src/ios/RNFetchBlobFS.h
  3. 25
    0
      src/ios/RNFetchBlobFS.m

+ 5
- 0
src/ios/RNFetchBlob/RNFetchBlob.m View File

470
     }
470
     }
471
 })
471
 })
472
 
472
 
473
+RCT_EXPORT_METHOD(df:(RCTResponseSenderBlock)callback
474
+{
475
+    [RNFetchBlobFS df:callback];
476
+})
477
+
473
 - (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
478
 - (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
474
     UIWindow *window = [UIApplication sharedApplication].keyWindow;
479
     UIWindow *window = [UIApplication sharedApplication].keyWindow;
475
     return window.rootViewController;
480
     return window.rootViewController;

+ 1
- 0
src/ios/RNFetchBlobFS.h View File

66
 //+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
66
 //+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
67
 + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
67
 + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
68
 + (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
68
 + (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
69
++ (void) df:(RCTResponseSenderBlock)callback;
69
 
70
 
70
 // constructor
71
 // constructor
71
 - (id) init;
72
 - (id) init;

+ 25
- 0
src/ios/RNFetchBlobFS.m View File

722
     }
722
     }
723
 }
723
 }
724
 
724
 
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
+
725
 + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest
750
 + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest
726
 {
751
 {
727
     int read = 0;
752
     int read = 0;