-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] Wrappers swift migration - part 5 #10641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 2 commits into
flutter:main
from
leancodepl:feature/camera-wrappers-swift-migration-part5
Dec 23, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...ndation/ios/camera_avfoundation/Sources/camera_avfoundation/CameraPermissionManager.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import AVFoundation | ||
| import Flutter | ||
|
|
||
| /// Completion handler for camera permission requests. | ||
| typealias CameraPermissionRequestCompletionHandler = (FlutterError?) -> Void | ||
|
|
||
| private enum Permission { | ||
| case camera | ||
| case audio | ||
| } | ||
|
|
||
| /// Manages camera and audio permission requests. | ||
| class CameraPermissionManager: NSObject { | ||
RobertOdrowaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let permissionService: PermissionServicing | ||
|
|
||
| init(permissionService: PermissionServicing) { | ||
| self.permissionService = permissionService | ||
| super.init() | ||
| } | ||
|
|
||
| /// Requests camera access permission. | ||
| /// | ||
| /// If it is the first time requesting camera access, a permission dialog will show up on the | ||
| /// screen. Otherwise AVFoundation simply returns the user's previous choice, and in this case the | ||
| /// user will have to update the choice in Settings app. | ||
| /// | ||
| /// @param handler if access permission is (or was previously) granted, completion handler will be | ||
| /// called without error; Otherwise completion handler will be called with error. Handler can be | ||
| /// called on an arbitrary dispatch queue. | ||
| func requestCameraPermission( | ||
| completionHandler handler: @escaping CameraPermissionRequestCompletionHandler | ||
| ) { | ||
| requestPermission(permission: .camera, handler: handler) | ||
| } | ||
|
|
||
| /// Requests audio access permission. | ||
| /// | ||
| /// If it is the first time requesting audio access, a permission dialog will show up on the | ||
| /// screen. Otherwise AVFoundation simply returns the user's previous choice, and in this case the | ||
| /// user will have to update the choice in Settings app. | ||
| /// | ||
| /// @param handler if access permission is (or was previously) granted, completion handler will be | ||
| /// called without error; Otherwise completion handler will be called with error. Handler can be | ||
| /// called on an arbitrary dispatch queue. | ||
| func requestAudioPermission( | ||
| completionHandler handler: @escaping CameraPermissionRequestCompletionHandler | ||
| ) { | ||
| requestPermission(permission: .audio, handler: handler) | ||
| } | ||
|
|
||
| private func requestPermission( | ||
| permission: Permission, | ||
| handler: @escaping CameraPermissionRequestCompletionHandler | ||
| ) { | ||
| let mediaType: AVMediaType = | ||
| switch permission { | ||
| case .audio: .audio | ||
| case .camera: .video | ||
| } | ||
|
|
||
| switch permissionService.authorizationStatus(for: mediaType) { | ||
| case .authorized: | ||
| handler(nil) | ||
|
|
||
| case .denied: | ||
| let flutterError = | ||
| switch permission { | ||
| case .audio: | ||
| FlutterError( | ||
| code: "AudioAccessDeniedWithoutPrompt", | ||
| message: | ||
| "User has previously denied the audio access request. Go to Settings to enable audio access.", | ||
| details: nil | ||
| ) | ||
| case .camera: | ||
| FlutterError( | ||
| code: "CameraAccessDeniedWithoutPrompt", | ||
| message: | ||
| "User has previously denied the camera access request. Go to Settings to enable camera access.", | ||
| details: nil | ||
| ) | ||
| } | ||
| handler(flutterError) | ||
|
|
||
| case .restricted: | ||
| let flutterError = | ||
| switch permission { | ||
| case .audio: | ||
| FlutterError( | ||
| code: "AudioAccessRestricted", | ||
| message: "Audio access is restricted.", | ||
| details: nil | ||
| ) | ||
| case .camera: | ||
| FlutterError( | ||
| code: "CameraAccessRestricted", | ||
| message: "Camera access is restricted.", | ||
| details: nil | ||
| ) | ||
| } | ||
| handler(flutterError) | ||
|
|
||
| case .notDetermined: | ||
| permissionService.requestAccess(for: mediaType) { granted in | ||
| // handler can be invoked on an arbitrary dispatch queue. | ||
| if granted { | ||
| handler(nil) | ||
| } else { | ||
| let flutterError = | ||
| switch permission { | ||
| case .audio: | ||
| FlutterError( | ||
| code: "AudioAccessDenied", | ||
| message: "User denied the audio access request.", | ||
| details: nil | ||
| ) | ||
| case .camera: | ||
| FlutterError( | ||
| code: "CameraAccessDenied", | ||
| message: "User denied the camera access request.", | ||
| details: nil | ||
| ) | ||
| } | ||
| handler(flutterError) | ||
| } | ||
| } | ||
|
|
||
| @unknown default: | ||
| assertionFailure("Unknown authorization status") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.