Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Commit

Permalink
simplest possible fix for #311 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveliles authored and wkh237 committed Apr 26, 2017
1 parent 016a480 commit 335d83d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions ios/RNFetchBlob/RNFetchBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ - (NSDictionary *)constantsToExport
#pragma mark - fs.stat
RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) callback)
{

[RNFetchBlobFS getPathFromUri:target completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
__block NSMutableArray * result;
if(path != nil)
Expand All @@ -309,14 +309,14 @@ - (NSDictionary *)constantsToExport
BOOL exist = nil;
BOOL isDir = nil;
NSError * error = nil;

exist = [fm fileExistsAtPath:path isDirectory:&isDir];
if(exist == NO) {
callback(@[[NSString stringWithFormat:@"failed to stat path `%@` for it is not exist or it is not exist", path]]);
return ;
}
result = [RNFetchBlobFS stat:path error:&error];

if(error == nil)
callback(@[[NSNull null], result]);
else
Expand Down Expand Up @@ -375,7 +375,7 @@ - (NSDictionary *)constantsToExport
#pragma mark - fs.cp
RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback)
{

// path = [RNFetchBlobFS getPathOfAsset:path];
[RNFetchBlobFS getPathFromUri:src completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
NSError * error = nil;
Expand All @@ -387,14 +387,14 @@ - (NSDictionary *)constantsToExport
else
{
BOOL result = [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:path] toURL:[NSURL fileURLWithPath:dest] error:&error];

if(error == nil)
callback(@[[NSNull null], @YES]);
else
callback(@[[error localizedDescription], @NO]);
}
}];

}


Expand Down Expand Up @@ -456,7 +456,7 @@ - (NSDictionary *)constantsToExport
else
bufferSize = 4096;
}

dispatch_async(fsQueue, ^{
[RNFetchBlobFS readStream:path encoding:encoding bufferSize:bufferSize tick:tick streamId:streamId bridgeRef:_bridge];
});
Expand All @@ -482,7 +482,7 @@ - (NSDictionary *)constantsToExport
#pragma mark - net.enableProgressReport
RCT_EXPORT_METHOD(enableProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
{

RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Download interval:interval count:count];
[RNFetchBlobNetwork enableProgressReport:taskId config:cfg];
}
Expand All @@ -509,9 +509,10 @@ - (NSDictionary *)constantsToExport
UIViewController *rootCtrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
documentController.delegate = self;
if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
dispatch_sync(dispatch_get_main_queue(), ^{
[documentController presentOptionsMenuFromRect:rootCtrl.view.bounds inView:rootCtrl.view animated:YES];
});
CGRect rect = CGRectMake(0.0, 0.0, 0.0, 0.0);
dispatch_sync(dispatch_get_main_queue(), ^{
[documentController presentOptionsMenuFromRect:rect inView:rootCtrl.view animated:YES];
});
resolve(@[[NSNull null]]);
} else {
reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
Expand All @@ -527,7 +528,7 @@ - (NSDictionary *)constantsToExport
// NSURL * url = [[NSURL alloc] initWithString:uri];
documentController = [UIDocumentInteractionController interactionControllerWithURL:url];
documentController.delegate = self;

if(scheme == nil || [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:scheme]]) {
dispatch_sync(dispatch_get_main_queue(), ^{
[documentController presentPreviewAnimated:YES];
Expand All @@ -550,7 +551,7 @@ - (NSDictionary *)constantsToExport
} else {
reject(@"RNFetchBlob could not open document", [error description], nil);
}

}


Expand Down

0 comments on commit 335d83d

Please sign in to comment.