Rachit
Rachit

Reputation: 842

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

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

Upvotes: 0

Views: 53

Answers (1)

Rakesh Patel
Rakesh Patel

Reputation: 1701

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.

Upvotes: 0

Related Questions