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

simplest possible fix for #311 #313

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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