Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rqeuest audio permission on create call instead of prepareForVideoRec…
…ording call
  • Loading branch information
hellohuanlin committed May 17, 2022
commit a169b344eb540328833f6c65696c11e1d95e8387
51 changes: 30 additions & 21 deletions packages/camera/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
[result sendNotImplemented];
}
} else if ([@"create" isEqualToString:call.method]) {
FLTRequestCameraPermissionWithCompletionHandler(^(FlutterError *error) {
// Create FLTCam only if granted camera access.
if (error) {
[result sendFlutterError:error];
} else {
[self createCameraOnSessionQueueWithCreateMethodCall:call result:result];
}
});
[self handleCreateMethodCall:call result:result];
} else if ([@"startImageStream" isEqualToString:call.method]) {
[_camera startImageStreamWithMessenger:_messenger];
[result sendSuccess];
Expand Down Expand Up @@ -194,19 +187,8 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
[_camera close];
[result sendSuccess];
} else if ([@"prepareForVideoRecording" isEqualToString:call.method]) {
// Setup audio capture session only if granted audio access.
FLTRequestAudioPermissionWithCompletionHandler(^(FlutterError *error) {
if (error) {
[result sendFlutterError:error];
} else {
// Permission completion handler may be called on arbitrary queue.
// Dispatch to `captureSessionQueue` to setup audio capture session.
dispatch_async(self.captureSessionQueue, ^{
[self.camera setUpCaptureSessionForAudio];
[result sendSuccess];
});
}
});
[self.camera setUpCaptureSessionForAudio];
[result sendSuccess];
} else if ([@"startVideoRecording" isEqualToString:call.method]) {
[_camera startVideoRecordingWithResult:result];
} else if ([@"stopVideoRecording" isEqualToString:call.method]) {
Expand Down Expand Up @@ -269,6 +251,33 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call
}
}

- (void)handleCreateMethodCall:(FlutterMethodCall *)call
result:(FLTThreadSafeFlutterResult *)result {
// Create FLTCam only if granted camera access (and audio access if audio is enabled)
FLTRequestCameraPermissionWithCompletionHandler(^(FlutterError *error) {
if (error) {
[result sendFlutterError:error];
} else {
// Request audio permission on `create` call with `enableAudio` argument instead of the
// `prepareForVideoRecording` call. This is because `prepareForVideoRecording` call is
// optional, and used as a workaround to fix a missing frame issue on iOS.
BOOL audioEnabled = [call.arguments[@"enableAudio"] boolValue];
if (audioEnabled) {
// Setup audio capture session only if granted audio access.
FLTRequestAudioPermissionWithCompletionHandler(^(FlutterError *error) {
if (error) {
[result sendFlutterError:error];
} else {
[self createCameraOnSessionQueueWithCreateMethodCall:call result:result];
}
});
} else {
[self createCameraOnSessionQueueWithCreateMethodCall:call result:result];
}
}
});
}

- (void)createCameraOnSessionQueueWithCreateMethodCall:(FlutterMethodCall *)createMethodCall
result:(FLTThreadSafeFlutterResult *)result {
dispatch_async(self.captureSessionQueue, ^{
Expand Down