Untitled
unknown
swift
3 years ago
2.1 kB
7
Indexable
let cameraAction = UIAlertAction(
title: Text.DynamicForm.FileUploader.uploadTypeCamera,
style: .default
) { [weak self] _ in
guard let self = self else {
return
}
if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
self.openCamera(delegate: delegate)
} else {
AVCaptureDevice.requestAccess(for: .video, completionHandler: { [weak self] granted in
if granted {
self?.openCamera(delegate: delegate)
} else {
self?.configureSettingsAlert(for: .camera)
}
})
}
}
let photosAction = UIAlertAction(
title: Text.DynamicForm.FileUploader.uploadTypePhotos,
style: .default
) { [weak self] _ in
guard let self = self else {
return
}
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized, .limited:
self.openPhotoLibrary(delegate: delegate)
case .notDetermined:
PHPhotoLibrary.requestAuthorization { [weak self] status in
if status == .authorized {
self?.openPhotoLibrary(delegate: delegate)
} else {
self?.configureSettingsAlert(for: .photos)
}
}
case .denied, .restricted:
self.configureSettingsAlert(for: .photos)
@unknown default:
break
}
}
#if !targetEnvironment(simulator)
alert.addAction(cameraAction)
#endif
alert.addAction(photosAction)
Editor is loading...