|
@@ -26,6 +26,7 @@
|
26
|
26
|
@implementation RNFetchBlob
|
27
|
27
|
|
28
|
28
|
@synthesize filePathPrefix;
|
|
29
|
+@synthesize documentController;
|
29
|
30
|
@synthesize bridge = _bridge;
|
30
|
31
|
|
31
|
32
|
- (dispatch_queue_t) methodQueue {
|
|
@@ -367,10 +368,44 @@ RCT_EXPORT_METHOD(slice:(NSString *)src dest:(NSString *)dest start:(nonnull NSN
|
367
|
368
|
[RNFetchBlobFS slice:src dest:dest start:start end:end encode:@"" resolver:resolve rejecter:reject];
|
368
|
369
|
})
|
369
|
370
|
|
370
|
|
-RCT_EXPORT_METHOD(openFile:(NSString*)uri {
|
371
|
|
- [[[RNFetchBlobFS alloc ] init ]openFile:uri];
|
|
371
|
+RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
372
|
+{
|
|
373
|
+
|
|
374
|
+ NSURL * url = [[NSURL alloc] initWithString:uri];
|
|
375
|
+ documentController = [UIDocumentInteractionController interactionControllerWithURL:url];
|
|
376
|
+ UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
|
|
377
|
+ documentController.delegate = self;
|
|
378
|
+ if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
|
|
379
|
+ [documentController presentOpenInMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view animated:YES];
|
|
380
|
+ resolve(@[[NSNull null]]);
|
|
381
|
+ } else {
|
|
382
|
+ reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
|
|
383
|
+ }
|
372
|
384
|
})
|
373
|
385
|
|
|
386
|
+# pragma mark - open file with UIDocumentInteractionController and delegate
|
|
387
|
+
|
|
388
|
+RCT_EXPORT_METHOD(previewDocument:(NSString*)uri scheme:(NSString *)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
389
|
+{
|
|
390
|
+
|
|
391
|
+ NSURL * url = [[NSURL alloc] initWithString:uri];
|
|
392
|
+ documentController = [UIDocumentInteractionController interactionControllerWithURL:url];
|
|
393
|
+ documentController.delegate = self;
|
|
394
|
+
|
|
395
|
+ if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
|
|
396
|
+ [documentController presentPreviewAnimated:YES];
|
|
397
|
+ resolve(@[[NSNull null]]);
|
|
398
|
+ } else {
|
|
399
|
+ reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
|
|
400
|
+ }
|
|
401
|
+})
|
|
402
|
+
|
|
403
|
+- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
|
|
404
|
+ UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
|
405
|
+ return window.rootViewController;
|
|
406
|
+}
|
|
407
|
+
|
|
408
|
+
|
374
|
409
|
#pragma mark RNFetchBlob private methods
|
375
|
410
|
|
376
|
411
|
|