iOS 图像选择器返回不存在的视频文件路径
iOS image picker returning non-existent file path for video
考虑以下方法,并对其行为进行注释。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Apparently valid URL, looks like
// "file:///private/var/mobile/Containers/Data/Application/.../filename.mov"
NSURL *videoURL = info[UIImagePickerControllerMediaURL];
// Always evaluates to false; no videos are saved
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoURL.absoluteString) {
UISaveVideoAtPathToSavedPhotosAlbum(videoURL.absoluteString, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
}
为什么这不起作用,我该如何解决?
顾名思义,方法 UIVideoAtPathIsCompatibleWithSavedPhotosAlbum()
和 UISaveVideoAtPathToSavedPhotosAlbum()
需要一个 路径 ,而不是 URL。 Not the same thing.
字符串
file:///private/var/mobile/Containers/Data/Application/.../filename.mov
是一个URL,由方案
组成
file://
和路径
/private/var/mobile/Containers/Data/Application/.../filename.mov
设计用于接受路径的函数在传递完整的 URL 时将无法正常工作。
要解决此问题,请将对 videoURL.absoluteString
的调用替换为 videoURL.path
。
考虑以下方法,并对其行为进行注释。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Apparently valid URL, looks like
// "file:///private/var/mobile/Containers/Data/Application/.../filename.mov"
NSURL *videoURL = info[UIImagePickerControllerMediaURL];
// Always evaluates to false; no videos are saved
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoURL.absoluteString) {
UISaveVideoAtPathToSavedPhotosAlbum(videoURL.absoluteString, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
}
为什么这不起作用,我该如何解决?
顾名思义,方法 UIVideoAtPathIsCompatibleWithSavedPhotosAlbum()
和 UISaveVideoAtPathToSavedPhotosAlbum()
需要一个 路径 ,而不是 URL。 Not the same thing.
字符串
file:///private/var/mobile/Containers/Data/Application/.../filename.mov
是一个URL,由方案
组成file://
和路径
/private/var/mobile/Containers/Data/Application/.../filename.mov
设计用于接受路径的函数在传递完整的 URL 时将无法正常工作。
要解决此问题,请将对 videoURL.absoluteString
的调用替换为 videoURL.path
。