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

58 Views Asked by At

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

There are 1 best solutions below

0
On

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.