我写了这段代码,但由于高内存消耗导致应用程序崩溃。
-(void)saveToDir
{
[[PHImageManager defaultManager] requestAVAssetForVideo:[assets objectAtIndex:indexPath.item] options:[PHVideoRequestOptions new] resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
dispatch_async(dispatch_get_main_queue(), ^
{
if ([asset isKindOfClass:[AVURLAsset class]])
{
NSURL *url = [(AVURLAsset*)asset URL];
urlFromLibrary=url;
AVAsset *asset=[selectedImageArray objectAtIndex:i];
NSURL *url = [(AVURLAsset*)asset URL];
NSString *filename = [[url path] lastPathComponent];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:filename];
NSArray *array=[NSArray arrayWithObjects:url,filePath, nil];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
if (data)
{
if([data writeToFile:filePath atomically:YES])
{
NSLog(@“write successfull”);
}
else{
NSLog(@“write failed”);
}
}
// [self downloadVideoAndSave:url :filePath];
}
}];
我写了上面这段代码,但应用程序崩溃,内存问题,所以更好的响应