When a video has been downloaded and ready to be cached to the file system, it first determines if the video should be exported a lower quality.
If not, the downloaded file is expected to be moved from its temporary download location (which is apparently random and provided by URLSession DownloadTask) to a more permanent location.
However, simply moving the file has the unintended possibility of collision. You can't move an item to a URL that already contains an item as evidenced by this error:
Error Domain=NSCocoaErrorDomain Code=516 "{FILE_NAME}"
couldn’t be moved to “{DIRECTORY_NAME}” because an item with the same name already exists."
UserInfo={NSSourceFilePathErrorKey={FILE_PATH}, NSUserStringVariant=(
Move
),
NSDestinationFilePath={DESTINATION_FILE_PATH}, NSFilePath={TEMPORARY_FILE_PATH}, NSUnderlyingError=0x280871860 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}
First check if the file exists or delete any files at that path before using the moveItem function
When a video has been downloaded and ready to be cached to the file system, it first determines if the video should be exported a lower quality.
If not, the downloaded file is expected to be moved from its temporary download location (which is apparently random and provided by URLSession DownloadTask) to a more permanent location.
However, simply moving the file has the unintended possibility of collision. You can't move an item to a URL that already contains an item as evidenced by this error:
First check if the file exists or delete any files at that path before using the
moveItem
function