首页 > 解决方案 > 我们可以重命名画廊的自定义相册中保存的视频名称吗?

问题描述

我希望你们都做得很棒

我目前正在开发视频编辑应用程序,这里有一个功能我需要重命名保存的视频名称

我的视频保存流程

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

任何人都可以有任何想法吗?

我需要帮助

标签: iosavplayer

解决方案


您可以选择视频并复制它

第一:第 1 步:使用 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)
}
}

最后一步:第4步:访问文件

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

给你


推荐阅读