소스 검색

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

Ben 8 년 전
부모
커밋
94db6670a4
2개의 변경된 파일22개의 추가작업 그리고 19개의 파일을 삭제
  1. 8
    6
      android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
  2. 14
    13
      ios/RNFetchBlob/RNFetchBlob.m

+ 8
- 6
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java 파일 보기

641
                         return;
641
                         return;
642
                     }
642
                     }
643
                     String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
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
                 // When the file is not found in media content database, check if custom path exists
654
                 // When the file is not found in media content database, check if custom path exists

+ 14
- 13
ios/RNFetchBlob/RNFetchBlob.m 파일 보기

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