Photos and Camera: PhotosPicker and Permissions

IOS Development 10 min min read Updated: Nov 16, 2026 Intermediate
Photos and Camera: PhotosPicker and Permissions
Intermediate Topic 4 of 6

PhotosPicker: No Permission Needed

PhotosPicker runs outside your app. Users pick the photos, and your app receives only those items. So you do not need to request photo library access.

swift import SwiftUI import PhotosUI struct AvatarPicker: View { @State private var selection: PhotosPickerItem? @State private var image: Image? var body: some View { VStack(spacing: 20) { if let image { image.resizable().scaledToFill() .frame(width: 160, height: 160) .clipShape(Circle()) } else { Image(systemName: "person.crop.circle") .font(.system(size: 120)) .foregroundStyle(.secondary) } PhotosPicker("Choose photo", selection: $selection, matching: .images) } .onChange(of: selection) { _, newItem in Task { if let data = try? await newItem?.loadTransferable(type: Data.self), let uiImage = UIImage(data: data) { image = Image(uiImage: uiImage) } } } } }

Multiple Photos

swift @State private var selections: [PhotosPickerItem] = [] PhotosPicker("Pick up to 5", selection: $selections, maxSelectionCount: 5, matching: .any(of: [.images, .not(.videos)]))

How Permissions Work

FeatureInfo key (reason text)
CameraNSCameraUsageDescription
MicrophoneNSMicrophoneUsageDescription
Photo library (full access)NSPhotoLibraryUsageDescription
Add photos onlyNSPhotoLibraryAddUsageDescription
Location in useNSLocationWhenInUseUsageDescription
ContactsNSContactsUsageDescription
Face IDNSFaceIDUsageDescription
Missing key = crash: If you use the camera but forget NSCameraUsageDescription, the app crashes the moment you access it. Always add the text first.

Camera Authorization

swift import AVFoundation func checkCamera() async -> Bool { switch AVCaptureDevice.authorizationStatus(for: .video) { case .authorized: return true case .notDetermined: return await AVCaptureDevice.requestAccess(for: .video) // shows the system prompt once case .denied, .restricted: return false @unknown default: return false } }

When the User Said No

iOS shows the permission prompt only once. After a refusal, guide the user to Settings.

swift VStack(spacing: 12) { Text("Camera access is off") Button("Open Settings") { if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) } } }

Simulator Limits

The Simulator has no real camera. Test camera code on a physical iPhone. The Simulator's photo library can be filled by dragging pictures onto it.

Best practice: Explain why you need access before you trigger the system prompt, for example on a short screen with a button. Users accept more often when the benefit is clear.

Conclusion

Use PhotosPicker for choosing pictures without permissions. For the camera and other sensors add usage descriptions, request access at the right moment and handle denial gracefully.

Quick Summary: PhotosPicker needs no permission, camera needs NSCameraUsageDescription, and a denied permission must be fixed in Settings.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators