Selaa lähdekoodia

Merge branch 'master' of github.com:wkh237/react-native-fetch-blob

Ben 7 vuotta sitten
vanhempi
commit
94db6670a4

+ 8
- 6
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Näytä tiedosto

@@ -641,12 +641,14 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
641 641
                         return;
642 642
                     }
643 643
                     String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
644
-                    Uri uri = Uri.parse(contentUri);
645
-                    Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
646
-                    // use default destination of DownloadManager
647
-                    if (cursor != null) {
648
-                        cursor.moveToFirst();
649
-                        filePath = cursor.getString(0);
644
+                    if (contentUri != null) {
645
+                        Uri uri = Uri.parse(contentUri);
646
+                        Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
647
+                        // use default destination of DownloadManager
648
+                        if (cursor != null) {
649
+                            cursor.moveToFirst();
650
+                            filePath = cursor.getString(0);
651
+                        }
650 652
                     }
651 653
                 }
652 654
                 // When the file is not found in media content database, check if custom path exists

+ 14
- 13
ios/RNFetchBlob/RNFetchBlob.m Näytä tiedosto

@@ -314,7 +314,7 @@ RCT_EXPORT_METHOD(ls:(NSString *)path callback:(RCTResponseSenderBlock) callback
314 314
 #pragma mark - fs.stat
315 315
 RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) callback)
316 316
 {
317
-    
317
+
318 318
     [RNFetchBlobFS getPathFromUri:target completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
319 319
         __block NSMutableArray * result;
320 320
         if(path != nil)
@@ -323,14 +323,14 @@ RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) call
323 323
             BOOL exist = nil;
324 324
             BOOL isDir = nil;
325 325
             NSError * error = nil;
326
-            
326
+
327 327
             exist = [fm fileExistsAtPath:path isDirectory:&isDir];
328 328
             if(exist == NO) {
329 329
                 callback(@[[NSString stringWithFormat:@"failed to stat path `%@` for it is not exist or it is not exist", path]]);
330 330
                 return ;
331 331
             }
332 332
             result = [RNFetchBlobFS stat:path error:&error];
333
-            
333
+
334 334
             if(error == nil)
335 335
                 callback(@[[NSNull null], result]);
336 336
             else
@@ -389,7 +389,7 @@ RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callb
389 389
 #pragma mark - fs.cp
390 390
 RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback)
391 391
 {
392
-    
392
+
393 393
 //    path = [RNFetchBlobFS getPathOfAsset:path];
394 394
     [RNFetchBlobFS getPathFromUri:src completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
395 395
         NSError * error = nil;
@@ -401,14 +401,14 @@ RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTRespons
401 401
         else
402 402
         {
403 403
             BOOL result = [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:path] toURL:[NSURL fileURLWithPath:dest] error:&error];
404
-            
404
+
405 405
             if(error == nil)
406 406
                 callback(@[[NSNull null], @YES]);
407 407
             else
408 408
                 callback(@[[error localizedDescription], @NO]);
409 409
         }
410 410
     }];
411
-    
411
+
412 412
 }
413 413
 
414 414
 
@@ -470,7 +470,7 @@ RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding
470 470
         else
471 471
             bufferSize = 4096;
472 472
     }
473
-    
473
+
474 474
     dispatch_async(fsQueue, ^{
475 475
         [RNFetchBlobFS readStream:path encoding:encoding bufferSize:bufferSize tick:tick streamId:streamId bridgeRef:_bridge];
476 476
     });
@@ -496,7 +496,7 @@ RCT_EXPORT_METHOD(cancelRequest:(NSString *)taskId callback:(RCTResponseSenderBl
496 496
 #pragma mark - net.enableProgressReport
497 497
 RCT_EXPORT_METHOD(enableProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
498 498
 {
499
-    
499
+
500 500
     RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Download interval:interval count:count];
501 501
     [RNFetchBlobNetwork enableProgressReport:taskId config:cfg];
502 502
 }
@@ -523,9 +523,10 @@ RCT_EXPORT_METHOD(previewDocument:(NSString*)uri scheme:(NSString *)scheme resol
523 523
     UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
524 524
     documentController.delegate = self;
525 525
     if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
526
-        dispatch_sync(dispatch_get_main_queue(), ^{
527
-            [documentController  presentOptionsMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view animated:YES];
528
-        });
526
+      CGRect rect = CGRectMake(0.0, 0.0, 0.0, 0.0);
527
+      dispatch_sync(dispatch_get_main_queue(), ^{
528
+          [documentController  presentOptionsMenuFromRect:rect inView:rootCtrl.view animated:YES];
529
+      });
529 530
         resolve(@[[NSNull null]]);
530 531
     } else {
531 532
         reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
@@ -541,7 +542,7 @@ RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme resolver
541 542
     // NSURL * url = [[NSURL alloc] initWithString:uri];
542 543
     documentController = [UIDocumentInteractionController interactionControllerWithURL:url];
543 544
     documentController.delegate = self;
544
-    
545
+
545 546
     if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
546 547
         dispatch_sync(dispatch_get_main_queue(), ^{
547 548
             [documentController presentPreviewAnimated:YES];
@@ -564,7 +565,7 @@ RCT_EXPORT_METHOD(excludeFromBackupKey:(NSString *)url resolver:(RCTPromiseResol
564 565
     } else {
565 566
         reject(@"RNFetchBlob could not open document", [error description], nil);
566 567
     }
567
-    
568
+
568 569
 }
569 570
 
570 571