Ben Hsieh 8 years ago
parent
commit
305bda6dbd
4 changed files with 24 additions and 1 deletions
  1. 4
    0
      src/ios/RNFetchBlob/RNFetchBlob.m
  2. 4
    1
      src/ios/RNFetchBlobFS.h
  3. 15
    0
      src/ios/RNFetchBlobFS.m
  4. 1
    0
      test/test-init.js

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

367
     [RNFetchBlobFS slice:src dest:dest start:start end:end encode:@"" resolver:resolve rejecter:reject];
367
     [RNFetchBlobFS slice:src dest:dest start:start end:end encode:@"" resolver:resolve rejecter:reject];
368
 })
368
 })
369
 
369
 
370
+RCT_EXPORT_METHOD(openFile:(NSString*)uri {
371
+    [[[RNFetchBlobFS alloc ] init ]openFile:uri];
372
+})
373
+
370
 #pragma mark RNFetchBlob private methods
374
 #pragma mark RNFetchBlob private methods
371
 
375
 
372
 
376
 

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

11
 
11
 
12
 #import <Foundation/Foundation.h>
12
 #import <Foundation/Foundation.h>
13
 #import "RCTBridgeModule.h"
13
 #import "RCTBridgeModule.h"
14
+#import <UIKit/UIKit.h>
14
 @import AssetsLibrary;
15
 @import AssetsLibrary;
15
 
16
 
16
-@interface RNFetchBlobFS : NSObject <NSStreamDelegate>  {
17
+@interface RNFetchBlobFS : NSObject <NSStreamDelegate, UIDocumentInteractionControllerDelegate>  {
17
     NSOutputStream * outStream;
18
     NSOutputStream * outStream;
18
     NSInputStream * inStream;
19
     NSInputStream * inStream;
19
     RCTResponseSenderBlock callback;
20
     RCTResponseSenderBlock callback;
82
 - (void) closeInStream;
83
 - (void) closeInStream;
83
 - (void) closeOutStream;
84
 - (void) closeOutStream;
84
 
85
 
86
+- (void) openFile:( NSString * _Nonnull ) uri;
87
+
85
 @end
88
 @end
86
 
89
 
87
 #endif /* RNFetchBlobFS_h */
90
 #endif /* RNFetchBlobFS_h */

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

730
     }
730
     }
731
 }
731
 }
732
 
732
 
733
+# pragma mark - open file with UIDocumentInteractionController and delegate
734
+
735
+- (void) openFile:(NSString *) uri
736
+{
737
+    NSURL * url = [[NSURL alloc] initWithString:uri];
738
+    UIDocumentInteractionController * docCtrl = [UIDocumentInteractionController interactionControllerWithURL:url];
739
+    docCtrl.delegate = self;
740
+    [docCtrl presentPreviewAnimated:YES];
741
+    
742
+}
743
+
744
+- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
745
+    return self;
746
+}
747
+
733
 @end
748
 @end

+ 1
- 0
test/test-init.js View File

69
 // require('./test-0.9.0')
69
 // require('./test-0.9.0')
70
 // require('./test-0.9.2')
70
 // require('./test-0.9.2')
71
 require('./test-0.10.0')
71
 require('./test-0.10.0')
72
+// require('./test-0.9.4')
72
 // require('./test-fetch')
73
 // require('./test-fetch')
73
 // require('./test-fs')
74
 // require('./test-fs')
74
 // require('./test-xmlhttp')
75
 // require('./test-xmlhttp')