This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Request access permission for audio #5766
Merged
fluttergithubbot
merged 5 commits into
flutter:main
from
hellohuanlin:camera_permission_for_audio
May 18, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8e213e
[camera]request access permission for audio
hellohuanlin 141025c
updates readme and example to add audio exception codes
hellohuanlin 67f9435
split audio and video request functions
hellohuanlin cb3ecc6
add back WithCompletionHandler
hellohuanlin a169b34
rqeuest audio permission on create call instead of prepareForVideoRec…
hellohuanlin 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,35 +5,83 @@ | |
@import AVFoundation; | ||
#import "CameraPermissionUtils.h" | ||
|
||
void FLTRequestCameraPermissionWithCompletionHandler( | ||
FLTCameraPermissionRequestCompletionHandler handler) { | ||
switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) { | ||
void FLTRequestPermission(BOOL forAudio, FLTCameraPermissionRequestCompletionHandler handler) { | ||
AVMediaType mediaType; | ||
if (forAudio) { | ||
mediaType = AVMediaTypeAudio; | ||
} else { | ||
mediaType = AVMediaTypeVideo; | ||
} | ||
|
||
switch ([AVCaptureDevice authorizationStatusForMediaType:mediaType]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh we should always check the status first, and only request the permission if it's in |
||
case AVAuthorizationStatusAuthorized: | ||
handler(nil); | ||
break; | ||
case AVAuthorizationStatusDenied: | ||
handler([FlutterError errorWithCode:@"CameraAccessDeniedWithoutPrompt" | ||
message:@"User has previously denied the camera access request. " | ||
@"Go to Settings to enable camera access." | ||
details:nil]); | ||
case AVAuthorizationStatusDenied: { | ||
FlutterError *flutterError; | ||
if (forAudio) { | ||
flutterError = | ||
[FlutterError errorWithCode:@"AudioAccessDeniedWithoutPrompt" | ||
message:@"User has previously denied the audio access request. " | ||
@"Go to Settings to enable audio access." | ||
details:nil]; | ||
} else { | ||
flutterError = | ||
[FlutterError errorWithCode:@"CameraAccessDeniedWithoutPrompt" | ||
message:@"User has previously denied the camera access request. " | ||
@"Go to Settings to enable camera access." | ||
details:nil]; | ||
} | ||
handler(flutterError); | ||
break; | ||
case AVAuthorizationStatusRestricted: | ||
handler([FlutterError errorWithCode:@"CameraAccessRestricted" | ||
message:@"Camera access is restricted. " | ||
details:nil]); | ||
} | ||
case AVAuthorizationStatusRestricted: { | ||
FlutterError *flutterError; | ||
if (forAudio) { | ||
flutterError = [FlutterError errorWithCode:@"AudioAccessRestricted" | ||
message:@"Audio access is restricted. " | ||
details:nil]; | ||
} else { | ||
flutterError = [FlutterError errorWithCode:@"CameraAccessRestricted" | ||
message:@"Camera access is restricted. " | ||
details:nil]; | ||
} | ||
handler(flutterError); | ||
break; | ||
} | ||
case AVAuthorizationStatusNotDetermined: { | ||
[AVCaptureDevice | ||
requestAccessForMediaType:AVMediaTypeVideo | ||
completionHandler:^(BOOL granted) { | ||
// handler can be invoked on an arbitrary dispatch queue. | ||
handler(granted ? nil | ||
: [FlutterError | ||
errorWithCode:@"CameraAccessDenied" | ||
message:@"User denied the camera access request." | ||
details:nil]); | ||
}]; | ||
[AVCaptureDevice requestAccessForMediaType:mediaType | ||
completionHandler:^(BOOL granted) { | ||
// handler can be invoked on an arbitrary dispatch queue. | ||
if (granted) { | ||
handler(nil); | ||
} else { | ||
FlutterError *flutterError; | ||
if (forAudio) { | ||
flutterError = [FlutterError | ||
errorWithCode:@"AudioAccessDenied" | ||
message:@"User denied the audio access request." | ||
details:nil]; | ||
} else { | ||
flutterError = [FlutterError | ||
errorWithCode:@"CameraAccessDenied" | ||
message:@"User denied the camera access request." | ||
details:nil]; | ||
} | ||
handler(flutterError); | ||
} | ||
}]; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void FLTRequestCameraPermissionWithCompletionHandler( | ||
FLTCameraPermissionRequestCompletionHandler handler) { | ||
FLTRequestPermission(/*forAudio*/ NO, handler); | ||
} | ||
|
||
void FLTRequestAudioPermissionWithCompletionHandler( | ||
FLTCameraPermissionRequestCompletionHandler handler) { | ||
FLTRequestPermission(/*forAudio*/ YES, handler); | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So per your design doc edits this will also be implemented for Android?
plugins/packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/CameraPermissions.java
Line 29 in 7686be7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, android also handles camera and audio permissions separately.