- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
- (void)videoPickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info
在 iOS 13 和其他 iOS 中返回不同的 URL。
知道为什么会发生这种情况吗?
iOS 13:
file:///private/var/mobile/Containers/Data/PluginKitPlugin/0849234B-837C-43ED-BEDD-DE4F79E7CE96/tmp/trim.B8AB021D-F4B6-4E50-A93C-8B7F7FB40A1C.MOV
file:///private/var/mobile/Containers/Data/Application/5AE52A95-6A2F-49A5-8210-D70E022E9A05/tmp/5A8D81B5-FC42-4228-9514-CD998A4E7FA9.MOV
这导致我出现错误,因为我没有 PluginKitPlugin
的权限。文件夹。
在这两种情况下,我都使用 imagePicker
选择视频.
最佳答案
我为此苦苦挣扎了几个晚上,终于解决了这个问题。
此处用例的差异之一是我将视频上传到 AWS S3。这是通过后台线程中的 S3 传输实用程序发生的。经过大量的实验和调试,这就是我的决定。
变化在于,在 iOS 13 中,图像选择器 Controller didFinishPickingMediaWithInfo 方法的 info[.mediaURL] 参数中返回的 mediaURL 指向“PluginKitsPlugin ”目录。我们的应用似乎很长时间都无法访问该位置。
示例:file:///private/var/mobile/Containers/Data/PluginKitPlugin/0849234B-837C-43ED-BEDD-DE4F79E7CE96/tmp/trim。 B8AB021D-F4B6-4E50-A93C-8B7F7FB40A1C.MOV
由于某种原因(也许其他人知道)只能暂时访问该 URL。这里的一些理论表明,关闭图像选择器 Controller 将取消分配 URL,从而使其无效。
根据这个理论,我尝试通过两种不同的方式解决这个问题:
最终解决问题的方法是将信息[.mediaURL]复制到我的应用程序临时文件夹中的另一个可用位置。
这是我用来将信息[.mediaURL]复制到我的应用程序临时文件夹的代码。
This function will copy a video file to a temporary location so that it remains accessbile for further handling such as an upload to S3.
- Parameter url: This is the url of the media item.
- Returns: Return a new URL for the local copy of the vidoe file.
*/
func createTemporaryURLforVideoFile(url: NSURL) -> NSURL {
/// Create the temporary directory.
let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
/// create a temporary file for us to copy the video to.
let temporaryFileURL = temporaryDirectoryURL.appendingPathComponent(url.lastPathComponent ?? "")
/// Attempt the copy.
do {
try FileManager().copyItem(at: url.absoluteURL!, to: temporaryFileURL)
} catch {
print("There was an error copying the video file to the temporary location.")
}
return temporaryFileURL as NSURL
}
此代码将文件复制到临时目录(如下所示),您的应用程序在其生命周期内可以访问该临时目录:文件:///private/var/mobile/Containers/Data/Application/5AE52A95-6A2F-49A5-8210-D70E022E9A05/tmp/5A8D81B5-FC42-4228-9514-CD998A4E7FA9.MOV
您会注意到,选择要上传的图像 (info[.imageURL]) 会在同一目录中返回一个文件。上传图像之前没有出现任何问题。
这样,S3 传输实用程序就能够在后台线程中访问该文件并完成将视频上传到 S3。
关于ios - didFinishPickingMediaWithInfo 在 iOS 13 中返回不同的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57798968/
我在我的应用程序中使用 UIImagePickerViewController 拍照,但是在支持多任务处理的 iOS4+ 中,我遇到了内存问题。如果您打开了很多应用程序,然后又打开了我的应用程序,则
我正在努力使用 捕获 4.0 中返回的图像 - (void)imagePickerController:(UIImagePickerController *)picker didFinishP
我基本上是在尝试从用户照片库(或相机)中“获取”图像。 问题是,在 iPad 上(兼容模式)时没有返回图像。 这是代码: - (void)imagePickerController:(UIImageP
我想知道是否有办法让 didFinishPickingMediaWithInfo 方法根据发件人执行不同的操作。 例如: 在一个ViewController中,我有一个相机按钮,当用户完成拍照时,di
我认为 UIImagePickerController 委托(delegate)方法(或任何 UIKit 委托(delegate)方法)在主线程中被调用。但是在这里,当从图库或相机中选取图像时,did
我正在尝试在imagePickerController:didFinishPickingMediaWithInfo中管理图像旋转,但经过多次尝试,我没有找到任何解决方案。我最后的尝试是: -(void
我正在将旋转轮按钮实现为我的相机中的录制按钮。但是在单击旋转 DidFinish 方法的中心按钮时没有调用。 旋转轮的使用来自 http://www.raywenderlich.com/9864/ho
它看起来像 didFinishPickingMediaWithInfo 函数正在进行无限循环,它最终崩溃并在控制台中显示错误: warning: could not execute support c
Bellow 是我的 didFinishPickingMediaWithInfo 方法,我知道我有很多不必要的代码,保留,发布等......但这是我可以让它工作的方式,我害怕在尝试时破坏它优化它。 谁
我有一个 UITableViewCell 按钮可以拍摄图像并将其放回单元格中。当我调用 UIImagePickerController 并拍摄图像时,它不会调用以下委托(delegate): func
我在使用 UIImagePickerController 时遇到问题。基本上,虽然选择器显示良好,但 UIImagePickerController didFinishPickingMediaWith
我有一个 View Controller ,它需要能够从相册和相机中选择图片。对于 didFinishPickingMediaWithInfo 我只能有 1 个委托(delegate)方法,虽然我可以
我有一个项目,其中有许多使用 imagePicker 的 View Controller 。每次,我都必须再次复制 didFinishPickingMediaWithInfo 并且只更改一些代码。 然
我有带有cameraOverlyView的UIImagePickerController。我向覆盖 View 添加了点击手势识别器 - 当用户点击 View 时,应停止并保存录制: let media
在我的应用程序上拍摄照片后,我试图关闭预览。我只想按下快门按钮,然后弹回显示 UIImagePickerController 的 UIViewController,而不显示图像预览以及“重拍”和“使用
我有一个简单的应用程序,您可以从照片库中选择现有视频,也可以使用 UIImagePickerController 拍摄视频。 我添加了以下代码,当我用相机制作新视频时,如果将来需要,我可以将它保存在照
关闭。这个问题需要debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
这似乎是一个简单的问题,我已经看到类似问题的答案,但答案不起作用(至少不再起作用)。我在 viewDidAppear 中有以下代码: UIImagePickerController *imagePic
我不断收到未使用的变量警告。我正在尝试显示模态视图,用户在其中选择一张照片,我想在 UIImageView 中使用所选图像。 不确定这些信息是否足够,但非常感谢任何帮助。 - (IBAction) b
我有一个带有四个选项卡的 tabBar 应用程序。每个选项卡在每个选项卡 View 的 UINavigationBar 左侧都有一个相机按钮。单击相机按钮,进入相机模式,拍照,最后选择“使用照片”后,
我是一名优秀的程序员,十分优秀!