0

writeToFile fails to save 4K video with 50 min recording in document directory

BOOL videoSuccess = [[NSData dataWithContentsOfURL:videoURL] writeToFile:videoPath atomically:YES];

So videoSuccess returns false

Video Url:

file:///private/var/mobile/Containers/Data/Application/5C6C1826-B1B9-4F8C-BEFA-8842166B38CC/tmp/output.mov

Video Path:

/var/mobile/Containers/Data/Application/5C6C1826-B1B9-4F8C-BEFA-8842166B38CC/Documents/20180808160025.mp4


Got solution: Use moveItemAtPath instead of writeToFile or copyItemAtPath

[[NSFileManager defaultManager] moveItemAtPath:videoURL toPath:videoPath error:&error];
Rachit
  • 814
  • 9
  • 19

1 Answers1

0

Whenever you try to copy content from one directory path to another at that time don't rewrite whole content just use copy method.

            do
            {
              try FileManager.default.copyItem(at: videoURL, to: videoPath)
             }
            catch
            {
                print(error.localizedDescription)
            }

And also check your url is getting proper or not.

Rakesh Patel
  • 1,673
  • 10
  • 27