Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 739c49c

Browse files
committed
updates readme and example to add audio exception codes
1 parent b6c2c53 commit 739c49c

File tree

7 files changed

+33
-16
lines changed

7 files changed

+33
-16
lines changed

packages/camera/camera/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,16 @@ Here is a list of all permission error codes that can be thrown:
8888

8989
- `CameraAccessDenied`: Thrown when user denies the camera access permission.
9090

91-
- `CameraAccessDeniedWithoutPrompt`: iOS only for now. Thrown when user has previously denied the permission. iOS does not allow prompting alert dialog a second time. Users will have to go to Settings > Privacy in order to enable camera access.
91+
- `CameraAccessDeniedWithoutPrompt`: iOS only for now. Thrown when user has previously denied the permission. iOS does not allow prompting alert dialog a second time. Users will have to go to Settings > Privacy > Camera in order to enable camera access.
9292

9393
- `CameraAccessRestricted`: iOS only for now. Thrown when camera access is restricted and users cannot grant permission (parental control).
9494

95+
- `AudioAccessDenied`: Thrown when user denies the audio access permission.
96+
97+
- `AudioAccessDeniedWithoutPrompt`: iOS only for now. Thrown when user has previously denied the permission. iOS does not allow prompting alert dialog a second time. Users will have to go to Settings > Privacy > Microphone in order to enable audio access.
98+
99+
- `AudioAccessRestricted`: iOS only for now. Thrown when audio access is restricted and users cannot grant permission (parental control).
100+
95101
- `cameraPermission`: Android and Web only. A legacy error code for all kinds of camera permission errors.
96102

97103
### Example

packages/camera/camera/example/ios/RunnerTests/CameraCaptureSessionQueueRaceConditionTests.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ - (void)testFixForCaptureSessionQueueNullPointerCrashDueToRaceCondition {
2929
result:^(id _Nullable result) {
3030
[disposeExpectation fulfill];
3131
}];
32-
[camera createCameraOnCaptureSessionQueueWithCreateMethodCall:createCall
33-
result:[[FLTThreadSafeFlutterResult alloc]
34-
initWithResult:^(
35-
id _Nullable result) {
36-
[createExpectation fulfill];
37-
}]];
32+
[camera createCameraOnSessionQueueWithCreateMethodCall:createCall
33+
result:[[FLTThreadSafeFlutterResult alloc]
34+
initWithResult:^(id _Nullable result) {
35+
[createExpectation fulfill];
36+
}]];
3837
[self waitForExpectationsWithTimeout:1 handler:nil];
3938
// `captureSessionQueue` must not be nil after `create` call. Otherwise a nil
4039
// `captureSessionQueue` passed into `AVCaptureVideoDataOutput::setSampleBufferDelegate:queue:`

packages/camera/camera/example/ios/RunnerTests/CameraMethodChannelTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (void)testCreate_ShouldCallResultOnMainThread {
3636
methodCallWithMethodName:@"create"
3737
arguments:@{@"resolutionPreset" : @"medium", @"enableAudio" : @(1)}];
3838

39-
[camera createCameraOnCaptureSessionQueueWithCreateMethodCall:call result:resultObject];
39+
[camera createCameraOnSessionQueueWithCreateMethodCall:call result:resultObject];
4040
[self waitForExpectationsWithTimeout:1 handler:nil];
4141

4242
// Verify the result

packages/camera/camera/example/lib/main.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
697697
// iOS only
698698
showInSnackBar('Camera access is restricted.');
699699
break;
700+
case 'AudioAccessDenied':
701+
showInSnackBar('You have denied audio access.');
702+
break;
703+
case 'AudioAccessDeniedWithoutPrompt':
704+
// iOS only
705+
showInSnackBar('Please go to Settings app to enable audio access.');
706+
break;
707+
case 'AudioAccessRestricted':
708+
// iOS only
709+
showInSnackBar('Audio access is restricted.');
710+
break;
700711
case 'cameraPermission':
701712
// Android & web only
702713
showInSnackBar('Unknown permission error.');

packages/camera/camera/ios/Classes/CameraPermissionUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ typedef void (^FLTCameraPermissionRequestCompletionHandler)(FlutterError *);
1313
/// screen. Otherwise AVFoundation simply returns the user's previous choice, and in this case the
1414
/// user will have to update the choice in Settings app.
1515
///
16-
///
1716
/// @param forAudio Requests for `AVMediaTypeAudio` permission if `forAudio` is true, and
1817
/// `AVMediaTypeVideo` permission otherwise.
1918
/// @param handler if access permission is (or was previously) granted, completion handler will be

packages/camera/camera/ios/Classes/CameraPlugin.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
137137
if (error) {
138138
[result sendFlutterError:error];
139139
} else {
140-
[self createCameraOnCaptureSessionQueueWithCreateMethodCall:call result:result];
140+
[self createCameraOnSessionQueueWithCreateMethodCall:call result:result];
141141
}
142142
});
143143
} else if ([@"startImageStream" isEqualToString:call.method]) {
@@ -194,11 +194,13 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
194194
[_camera close];
195195
[result sendSuccess];
196196
} else if ([@"prepareForVideoRecording" isEqualToString:call.method]) {
197+
// Setup audio capture session only if granted audio access
197198
FLTRequestCameraPermission(/*forAudio*/ true, ^(FlutterError *error) {
198-
// Setup audio capture session only if granted audio access
199199
if (error) {
200200
[result sendFlutterError:error];
201201
} else {
202+
// Permission completion handler may be called on arbitrary queue.
203+
// Dispatch to `captureSessionQueue` to setup audio capture session.
202204
dispatch_async(self.captureSessionQueue, ^{
203205
[self.camera setUpCaptureSessionForAudio];
204206
[result sendSuccess];
@@ -267,8 +269,8 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
267269
}
268270
}
269271

270-
- (void)createCameraOnCaptureSessionQueueWithCreateMethodCall:(FlutterMethodCall *)createMethodCall
271-
result:(FLTThreadSafeFlutterResult *)result {
272+
- (void)createCameraOnSessionQueueWithCreateMethodCall:(FlutterMethodCall *)createMethodCall
273+
result:(FLTThreadSafeFlutterResult *)result {
272274
dispatch_async(self.captureSessionQueue, ^{
273275
NSString *cameraName = createMethodCall.arguments[@"cameraName"];
274276
NSString *resolutionPreset = createMethodCall.arguments[@"resolutionPreset"];

packages/camera/camera/ios/Classes/CameraPlugin_Test.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
/// that triggered the orientation change.
3939
- (void)orientationChanged:(NSNotification *)notification;
4040

41-
/// Creates FLTCam on capture session queue and reports the creation result.
41+
/// Creates FLTCam on session queue and reports the creation result.
4242
/// @param createMethodCall the create method call
4343
/// @param result a thread safe flutter result wrapper object to report creation result.
44-
- (void)createCameraOnCaptureSessionQueueWithCreateMethodCall:(FlutterMethodCall *)createMethodCall
45-
result:(FLTThreadSafeFlutterResult *)result;
44+
- (void)createCameraOnSessionQueueWithCreateMethodCall:(FlutterMethodCall *)createMethodCall
45+
result:(FLTThreadSafeFlutterResult *)result;
4646

4747
@end

0 commit comments

Comments
 (0)