Вы можете выбрать видео и скопировать его с помощью
Первый: Шаг 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)
}
Вот, пожалуйста,