如何使用没有内存问题的NsData在文档目录中保存多个大尺寸视频?

时间:2017-05-19 11:46:29

标签: ios objective-c video nsdata document

我写了这段代码,但由于高内存消耗导致应用程序崩溃。

 -(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];

                      }
}];

我写了上面这段代码,但应用程序崩溃,内存问题,所以更好的响应

0 个答案:

没有答案