从UIImagePickerController中选择后,如何删除本地视频文件?

时间:2018-06-01 21:55:13

标签: ios swift avfoundation uiimagepickercontroller

在我的应用中,我让用户使用UIImagePickerController从他们的库中选择一个视频。在编辑并选择它之后,它会在UIView中播放,以便在上传之前进行预览。我的问题是,在用户上传视频后,我认为视频仍然存储在应用存储中。我想在上传到数据库后将其从应用程序存储中删除。有没有办法在使用后删除videoURL或AVAsset。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let videoURL = info[UIImagePickerControllerMediaURL] as! URL
    video = AVAsset(url: videoURL)
    let item = AVPlayerItem(asset: video)
    self.player = AVPlayer(playerItem: item)
    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = uploadButton.bounds
    playerLayer.videoGravity = .resizeAspectFill
    playerLayer.masksToBounds = true
    uploadButton.layer.addSublayer(playerLayer)
    uploadButton.isEnabled = false
    NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) { _ in
        self.player.seek(to: kCMTimeZero)
        self.player.play()
    }
    player.play()

    let uButton = UIBarButtonItem(title: "Upload", style: .plain, target: self, action: #selector(handleUpload))
    navigationItem.rightBarButtonItem = uButton
    newVideoURL = videoURL
    dismiss(animated: true, completion: nil)
}

不完全确定视频是否保存在应用存储空间中,但我发现在我上传的每个视频后它会占用越来越多的空间。

提前致谢。

0 个答案:

没有答案