Added rejection and errors for copyAssetsVideoIOS

This commit is contained in:
Sebastian Makinson 2017-11-03 08:36:20 -06:00
parent 75a8c44ca8
commit c6ec354f2d
2 changed files with 55 additions and 50 deletions

View File

@ -456,7 +456,7 @@ To copy a video from assets-library and save it as a mp4-file, refer to copyAsse
Further information: https://developer.apple.com/reference/photos/phimagemanager/1616964-requestimageforasset
The promise will on success return the final destination of the file, as it was defined in the destPath-parameter.
### copyAssetsVideoIOS(videoUri: string, destPath: string)
### copyAssetsVideoIOS(videoUri: string, destPath: string): Promise<string>
iOS-only: copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...'
to a specific destination.

View File

@ -715,11 +715,10 @@ RCT_EXPORT_METHOD(copyAssetsVideoIOS: (NSString *) imageUri
atFilepath: (NSString *) destination
resolver: (RCTPromiseResolveBlock) resolve
rejecter: (RCTPromiseRejectBlock) reject)
{
NSURL* url = [NSURL URLWithString:imageUri];
__block NSURL* videoURL = [NSURL URLWithString:destination];
__block NSError *error = nil;
PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
PHAsset *phAsset = [phAssetFetchResult firstObject];
dispatch_group_t group = dispatch_group_create();
@ -732,7 +731,7 @@ RCT_EXPORT_METHOD(copyAssetsVideoIOS: (NSString *) imageUri
NSLog(@"Final URL %@",url);
NSData *videoData = [NSData dataWithContentsOfURL:url];
BOOL writeResult = [videoData writeToFile:destination atomically:true];
BOOL writeResult = [videoData writeToFile:destination options:NSDataWritingAtomic error:&error];
if(writeResult) {
NSLog(@"video success");
@ -744,7 +743,13 @@ RCT_EXPORT_METHOD(copyAssetsVideoIOS: (NSString *) imageUri
}
}];
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
resolve(destination);
if (error) {
NSLog(@"RNFS: %@", error);
return [self reject:reject withError:error];
}
return resolve(destination);
}
RCT_EXPORT_METHOD(touch:(NSString*)filepath