How do I request camera, microphone, and photo permissions?

In iOS development, it's essential to request permissions for accessing the camera, microphone, and photo library. Below is an example of how you can implement these requests in Swift.

import AVFoundation import Photos // Request camera permission AVCaptureDevice.requestAccess(for: .video) { response in if response { print("Camera access granted") } else { print("Camera access denied") } } // Request microphone permission AVAudioSession.sharedInstance().requestRecordPermission { response in if response { print("Microphone access granted") } else { print("Microphone access denied") } } // Request photo library permission PHPhotoLibrary.requestAuthorization { status in switch status { case .authorized: print("Photo library access granted") case .denied, .restricted: print("Photo library access denied") case .notDetermined: print("Photo library access not determined") @unknown default: fatalError("Unknown authorization status") } }

camera permissions microphone permissions photo library permissions Swift permissions iOS permission requests