0

I'm getting paths in an iOS app like:

AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSString *filePath = [urlAsset.URL path];
NSURL *videoUrl = [[NSURL alloc] initFileURLWithPath:filePath];

Result:

file:///var/mobile/Media/DCIM/105APPLE/IMG_5255.MOV

This app uploads files, in this case a video, but once I delete the video and go back to the app, this causes issues at the time that the app tries to upload the erased file, is there a way to check if the file exists to prevent issues while running the app? And also does the path changes when it's moved to "Recently Deleted" folder using iOS > 10?

In android is simple as

File file = new File(filePath);
if(file.exists())      
//Do something
else
// Do something else.
CGR
  • 370
  • 1
  • 4
  • 18

1 Answers1

1

Use either checkResourceIsReachableAndReturnError: or fileExistsAtPath:.

if([videoUrl checkResourceIsReachableAndReturnError:NULL] == YES) {
    //Use file
}

or

if([[NSFileManager defaultManager] fileExistsAtPath:videoUrl.path] {
    //Use file
}
Léo Natan
  • 56,823
  • 9
  • 150
  • 195