mirror of
https://github.com/status-im/react-native-fs.git
synced 2025-02-28 23:10:29 +00:00
Added rejection and errors for copyAssetsVideoIOS
This commit is contained in:
parent
75a8c44ca8
commit
c6ec354f2d
@ -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
|
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.
|
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?...'
|
iOS-only: copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...'
|
||||||
to a specific destination.
|
to a specific destination.
|
||||||
|
@ -715,11 +715,10 @@ RCT_EXPORT_METHOD(copyAssetsVideoIOS: (NSString *) imageUri
|
|||||||
atFilepath: (NSString *) destination
|
atFilepath: (NSString *) destination
|
||||||
resolver: (RCTPromiseResolveBlock) resolve
|
resolver: (RCTPromiseResolveBlock) resolve
|
||||||
rejecter: (RCTPromiseRejectBlock) reject)
|
rejecter: (RCTPromiseRejectBlock) reject)
|
||||||
|
|
||||||
{
|
{
|
||||||
NSURL* url = [NSURL URLWithString:imageUri];
|
NSURL* url = [NSURL URLWithString:imageUri];
|
||||||
__block NSURL* videoURL = [NSURL URLWithString:destination];
|
__block NSURL* videoURL = [NSURL URLWithString:destination];
|
||||||
|
__block NSError *error = nil;
|
||||||
PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
|
PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
|
||||||
PHAsset *phAsset = [phAssetFetchResult firstObject];
|
PHAsset *phAsset = [phAssetFetchResult firstObject];
|
||||||
dispatch_group_t group = dispatch_group_create();
|
dispatch_group_t group = dispatch_group_create();
|
||||||
@ -732,7 +731,7 @@ RCT_EXPORT_METHOD(copyAssetsVideoIOS: (NSString *) imageUri
|
|||||||
NSLog(@"Final URL %@",url);
|
NSLog(@"Final URL %@",url);
|
||||||
NSData *videoData = [NSData dataWithContentsOfURL:url];
|
NSData *videoData = [NSData dataWithContentsOfURL:url];
|
||||||
|
|
||||||
BOOL writeResult = [videoData writeToFile:destination atomically:true];
|
BOOL writeResult = [videoData writeToFile:destination options:NSDataWritingAtomic error:&error];
|
||||||
|
|
||||||
if(writeResult) {
|
if(writeResult) {
|
||||||
NSLog(@"video success");
|
NSLog(@"video success");
|
||||||
@ -744,7 +743,13 @@ RCT_EXPORT_METHOD(copyAssetsVideoIOS: (NSString *) imageUri
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
|
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
|
RCT_EXPORT_METHOD(touch:(NSString*)filepath
|
||||||
|
Loading…
x
Reference in New Issue
Block a user