Ben Hsieh 8 лет назад
Родитель
Сommit
305bda6dbd
4 измененных файлов: 24 добавлений и 1 удалений
  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 Просмотреть файл

@@ -367,6 +367,10 @@ RCT_EXPORT_METHOD(slice:(NSString *)src dest:(NSString *)dest start:(nonnull NSN
367 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 374
 #pragma mark RNFetchBlob private methods
371 375
 
372 376
 

+ 4
- 1
src/ios/RNFetchBlobFS.h Просмотреть файл

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

+ 15
- 0
src/ios/RNFetchBlobFS.m Просмотреть файл

@@ -730,4 +730,19 @@ NSMutableDictionary *fileStreams = nil;
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 748
 @end

+ 1
- 0
test/test-init.js Просмотреть файл

@@ -69,6 +69,7 @@ describe('GET image from server', (report, done) => {
69 69
 // require('./test-0.9.0')
70 70
 // require('./test-0.9.2')
71 71
 require('./test-0.10.0')
72
+// require('./test-0.9.4')
72 73
 // require('./test-fetch')
73 74
 // require('./test-fs')
74 75
 // require('./test-xmlhttp')