I’m new to swiftUI and I’m constructing an expense tracker app to be taught. I need the consumer to have the ability to take a picture of a receipt or choose a picture utilizing the photopicker.
At present each implementations work however there’s a slight problem.
When the consumer presses take picture the permissions alert shows asking the consumer if they might give the applying permission to make use of the digicam. In the event that they choose sure the photopicker shows to pick out a photograph reasonably than the precise digicam performance.If the consumer then clicks cancel and presses take picture the digicam shows appropriately because it ought to.
How do I eliminate this bug and permit the digicam to show as quickly as permission is granted? I attempted including a delay with dispatch queue however this didn’t work. Under is my present code.
.default(Textual content("Take Picture")) {
let cameraAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
swap cameraAuthorizationStatus {
case .notDetermined:
// Request permission for the digicam
AVCaptureDevice.requestAccess(for: .video) { granted in
DispatchQueue.primary.async {
if granted {
if UIImagePickerController.isSourceTypeAvailable(.digicam) {
sourceType = .digicam
showImagePicker = true
} else {
showPermissionAlert = true
permissionAlertMessage = "Digital camera just isn't out there on this gadget."
showSettingsButton = false // No want for a Settings button
}
} else {
showPermissionAlert = true
permissionAlertMessage = "Digital camera entry has been denied. Please allow it in Settings."
showSettingsButton = true // Embody a Settings button
}
}
}
case .approved:
// Permission already granted
if UIImagePickerController.isSourceTypeAvailable(.digicam) {
sourceType = .digicam
showImagePicker = true
} else {
showPermissionAlert = true
permissionAlertMessage = "Digital camera just isn't out there on this gadget."
showSettingsButton = false // No want for a Settings button
}
case .denied, .restricted:
// Permission denied or restricted
showPermissionAlert = true
permissionAlertMessage = "Digital camera entry has been denied. Please allow it in Settings."
showSettingsButton = true // Embody a Settings button
@unknown default:
showPermissionAlert = true
permissionAlertMessage = "An unknown error occurred. Please strive once more."
showSettingsButton = false // Default to no Settings button
}
}