我们可以重命名保存在自定义相册库中的视频名称吗?

时间:2018-10-29 07:20:15

标签: ios avplayer

希望大家都做得很棒

我目前正在使用Video Editing App,这里有一项功能需要重命名保存的视频名称

我保存视频的流程

  • 选择多张图片-在文档目录上创建视频-创建资产并保存在我的自定义相册中,库里

我进行了很多搜索,但没有得到任何解释我所需功能的特定链接或代码。

有人可以有什么主意吗?

我需要帮助

1 个答案:

答案 0 :(得分:0)

您可以选择视频并使用复制它

第一步:第一步:使用UIAlertController创建操作表

func showAttachmentActionSheet(vc: UIViewController) {
    currentVC = vc
    let actionSheet = UIAlertController(title: Constants.actionFileTypeHeading, message: Constants.actionFileTypeDescription, preferredStyle: .actionSheet)

    actionSheet.addAction(UIAlertAction(title: Constants.camera, style: .default, handler: { (action) -> Void in
        self.authorisationStatus(attachmentTypeEnum: .camera, vc: self.currentVC!)
    }))

    actionSheet.addAction(UIAlertAction(title: Constants.phoneLibrary, style: .default, handler: { (action) -> Void in
        self.authorisationStatus(attachmentTypeEnum: .photoLibrary, vc: self.currentVC!)
    }))

    actionSheet.addAction(UIAlertAction(title: Constants.video, style: .default, handler: { (action) -> Void in
        self.authorisationStatus(attachmentTypeEnum: .video, vc: self.currentVC!)

    }))

    actionSheet.addAction(UIAlertAction(title: Constants.file, style: .default, handler: { (action) -> Void in
        self.documentPicker()
    }))

    actionSheet.addAction(UIAlertAction(title: Constants.cancelBtnTitle, style: .cancel, handler: nil))

    vc.present(actionSheet, animated: true, completion: nil)
}

首先:步骤2:检查授权状态 转到Info.plist并添加这些内容行

Privacy — Camera Usage Description 
Privacy — Photo Library Usage Description

并添加这些说明

$(PRODUCT_NAME) would like to access your camera
$(PRODUCT_NAME) would like to access your photo.

然后添加这些功能

func authorisationStatus(attachmentTypeEnum: AttachmentType, vc: UIViewController){
    currentVC = vc
    if attachmentTypeEnum ==  AttachmentType.camera{
        let status = AVCaptureDevice.authorizationStatus(for: .video)
        switch status{
        case .authorized: // The user has previously granted access to the camera.
            self.openCamera(currentVC)

        case .notDetermined: // The user has not yet been asked for camera access.
            AVCaptureDevice.requestAccess(for: .video) { granted in
                if granted {
                    self.openCamera(self.currentVC)
                }
            }
        //denied - The user has previously denied access.
        //restricted - The user can't grant access due to restrictions.
        case .denied, .restricted:
            self.addAlertForSettings(attachmentTypeEnum)
            return

        default:
            break
        }
    }else if attachmentTypeEnum == AttachmentType.photoLibrary || attachmentTypeEnum == AttachmentType.video{
        let status = PHPhotoLibrary.authorizationStatus()
        switch status{
        case .authorized:
            if attachmentTypeEnum == AttachmentType.photoLibrary{
                photoLibrary()
            }

            if attachmentTypeEnum == AttachmentType.video{
                videoLibrary()
            }
        case .denied, .restricted:
            self.addAlertForSettings(attachmentTypeEnum)
        case .notDetermined:
            PHPhotoLibrary.requestAuthorization({ (status) in
                if status == PHAuthorizationStatus.authorized{
                    // photo library access given
                    self.photoLibrary()
                }
                if attachmentTypeEnum == AttachmentType.video{
                    self.videoLibrary()
                }
            })
        default:
            break
        }
    }
}

带有这个枚举

enum AttachmentType: String{
   case camera, video, photoLibrary
}

第3步:访问图库

func photoLibrary(){
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
    let myPickerController = UIImagePickerController()
    myPickerController.delegate = self
    myPickerController.sourceType = .photoLibrary
    currentVC?.present(myPickerController, animated: true, completion: nil)
}
}

最后一步:step4:访问文件

func documentPicker(){
    let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
    importMenu.delegate = self
    importMenu.modalPresentationStyle = .formSheet
    currentVC?.present(importMenu, animated: true, completion: nil)
}

去那里