Repository navigation
Closed
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolee: device-specificOnly manifests on certain devicesOnly manifests on certain devicesp: cameraThe camera pluginThe camera pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyteam-iosOwned by iOS platform teamOwned by iOS platform teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
Description
Steps to reproduce
- create a new flutter project
flutter create example - copy the code from
samplecode to main.dart - update camera & microphone usage description in Info.plist
- build the project and run in real device iPhone 16 (iOS Version: 18.0)
- click the take picture button at bottom right
camera: ^0.11.0+2only camera com.apple.avfoundation.avcapturedevice.built-in_video:5 has problem.
It throws exception CameraException(Error -11800, The operation could not be completed).
Maybe we shouldn't use highResolutionPhotoEnabled in method captureToFileWithCompletion for latest iOS versions since it already deprecated and support up to iOS 16.0.
Error from objective-c code:
// camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.m
__weak typeof(self) weakSelf = self;
FLTSavePhotoDelegate *savePhotoDelegate = [[FLTSavePhotoDelegate alloc]
initWithPath:path
ioQueue:self.photoIOQueue
completionHandler:^(NSString *_Nullable path, NSError *_Nullable error) {
typeof(self) strongSelf = weakSelf;
if (!strongSelf) return;
dispatch_async(strongSelf.captureSessionQueue, ^{
// cannot use the outter `strongSelf`
typeof(self) strongSelf = weakSelf;
if (!strongSelf) return;
[strongSelf.inProgressSavePhotoDelegates removeObjectForKey:@(settings.uniqueID)];
});
NSLog(@">>> error: %@", error);
if (error) {
completion(nil, FlutterErrorFromNSError(error));
} else {
NSAssert(path, @"Path must not be nil if no error.");
completion(path, nil);
}
}];>>> error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x3031fe760 {Error Domain=NSOSStatusErrorDomain Code=-73720 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-73720), AVErrorRecordingFailureDomainKey=4, NSLocalizedDescription=The operation could not be completed}Thank you for your tremendous help and contributions to the project!
Expected results
Expect return an image file after calling _contoller.takePicture() without exceptions.
Actual results
when calling _controller.takePicture() it throws exception CameraException(Error -11800, The operation could not be completed).
Code sample
Code sample
import 'dart:async';
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final cameras = await availableCameras();
final firstCamera = cameras.firstWhere(
(c) => c.name.endsWith(':5'),
orElse: () => cameras.first,
);
for (final camera in cameras) {
debugPrint('Available camera: ${camera.name}');
}
debugPrint('Using camera: ${firstCamera.name}'); // com.apple.avfoundation.avcapturedevice.built-in_video:5
runApp(
MaterialApp(
theme: ThemeData.dark(),
home: TakePictureScreen(
camera: firstCamera,
),
),
);
}
class TakePictureScreen extends StatefulWidget {
const TakePictureScreen({
super.key,
required this.camera,
});
final CameraDescription camera;
@override
TakePictureScreenState createState() => TakePictureScreenState();
}
class TakePictureScreenState extends State<TakePictureScreen> {
late CameraController _controller;
late Future<void> _initializeControllerFuture;
@override
void initState() {
super.initState();
_controller = CameraController(widget.camera, ResolutionPreset.max);
_initializeControllerFuture = _controller.initialize();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Take a picture')),
body: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return CameraPreview(_controller);
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
try {
await _initializeControllerFuture;
final image = await _controller.takePicture();
if (!context.mounted) return;
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(
imagePath: image.path,
),
),
);
} catch (e) {
print(e);
}
},
child: const Icon(Icons.camera_alt),
),
);
}
}
class DisplayPictureScreen extends StatelessWidget {
final String imagePath;
const DisplayPictureScreen({super.key, required this.imagePath});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Display the Picture')),
body: Image.file(File(imagePath)),
);
}
}Screenshots or Video
Screenshots / Video demonstration
The preview was fine, but when tap the button on bottom right to take a picture will throw exception.
Logs
Logs
Launching lib/main.dart on iPhone16 in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: **********
Running Xcode build...
Xcode build done. 9.8s
Installing and launching...
You may be prompted to give access to control Xcode. Flutter uses Xcode to run your app. If access is not allowed, you can change this through your Settings > Privacy & Security > Automation.
Debug service listening on ws://127.0.0.1:64936/***********=/ws
Syncing files to device iPhone16...
flutter: Available camera: com.apple.avfoundation.avcapturedevice.built-in_video:0
flutter: Available camera: com.apple.avfoundation.avcapturedevice.built-in_video:1
flutter: Available camera: com.apple.avfoundation.avcapturedevice.built-in_video:2
flutter: Available camera: com.apple.avfoundation.avcapturedevice.built-in_video:5
flutter: Using camera: com.apple.avfoundation.avcapturedevice.built-in_video:5
flutter: CameraException(Error -11800, The operation could not be completed)
Flutter Doctor output
Doctor output
> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.1, on macOS 15.0.1 24A348 darwin-arm64, locale en-CA)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] Connected device (6 available)
[✓] Network resources
• No issues found!
> flutter --version
Flutter 3.24.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5874a72aa4 (7 weeks ago) • 2024-08-20 16:46:00 -0500
Engine • revision c9b9d5780d
Tools • Dart 3.5.1 • DevTools 2.37.2
Metadata
Metadata
Assignees
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolee: device-specificOnly manifests on certain devicesOnly manifests on certain devicesp: cameraThe camera pluginThe camera pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyteam-iosOwned by iOS platform teamOwned by iOS platform teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
Activity
huycozy commentedon Oct 8, 2024
Thank you for the report! I don't have such a device to give this a test. Marking this as a device-specific issue for other's input.
ming-chu commentedon Oct 8, 2024
well, Code=-11800 is AVErrorUnknown
I have no clue for it so far...🫠
mkarapetyan-clgx commentedon Oct 16, 2024
It can be solved when you set ResolutionPreset non
.maxvalue, something like this:CameraController(camera, ResolutionPreset.veryHigh, imageFormatGroup: ImageFormatGroup.jpeg);NOTE: changing ResolutionPreset causes aspect ratio changes
ming-chu commentedon Oct 17, 2024
@mkarapetyan-clgx Yes, I used other
ResolutionPresetvalue as a workaround.But I think this is not a normal behavior to throw an exception when using
.max.Brysenp commentedon Oct 21, 2024
I'm able to replicate the issue reported by @ming-chu on an iPhone 16 Pro using the following camera package version:
Here are the relevant logs and Flutter doctor output:
Logs
Doctor output
Has there been any progress on this issue? I'd be happy to provide any additional information or assist with testing if needed.
ming-chu commentedon Oct 21, 2024
I thinks the highResolutionPhotoEnabled is already deprecated but we still using it. I am not sure if this is the root cause.
https://github.com/flutter/packages/blob/dafd7530115768e56abc576a6c58dfb96f8f767f/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.m#L357-L363
Brysenp commentedon Nov 5, 2024
I believe the issue was related to a bug in iOS 18. This bug seems to have been fixed in iOS 18.1.
@ming-chu, could you please confirm if this is correct?
ming-chu commentedon Nov 27, 2024
@Brysenp
I tested with
iOS 18.0.1 (22A3370)and still have error when taking photo with cameracom.apple.avfoundation.avcapturedevice.built-in_video:5Do you have any ideas?
jmagman commentedon Dec 20, 2024
@ming-chu Can you try on iOS 18.1, since that's the version @Brysenp is reporting it fixed in?
Ideally we would pass through a better error message, if nothing else.
I filed #160687 to audit for the deprecated APIs.
github-actions commentedon Jan 10, 2025
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
Thanks for your contribution.
github-actions commentedon Jan 25, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.