Skip to content

iPhone 16 takePicture() with ResolutionPreset.max and camera built-in_video:5 throw CameraException #156373

Closed

Description

@ming-chu

Steps to reproduce

  1. create a new flutter project flutter create example
  2. copy the code from sample code to main.dart
  3. update camera & microphone usage description in Info.plist
  4. build the project and run in real device iPhone 16 (iOS Version: 18.0)
  5. click the take picture button at bottom right
  camera: ^0.11.0+2

only 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.

image image

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.
IMG_0003

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

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Oct 8, 2024
  2. huycozy commented on Oct 8, 2024

    @huycozy
    Member

    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.

  3. added
    c: crashStack traces logged to the console
    platform-iosiOS applications specifically
    packageflutter/packages repository. See also p: labels.
    fyi-ecosystemFor the attention of Ecosystem team
    team-iosOwned by iOS platform team
    and removed
    in triagePresently being triaged by the triage team
    on Oct 8, 2024
  4. ming-chu commented on Oct 8, 2024

    @ming-chu
    Author

    well, Code=-11800 is AVErrorUnknown

    I have no clue for it so far...🫠

  5. mkarapetyan-clgx commented on Oct 16, 2024

    @mkarapetyan-clgx

    It can be solved when you set ResolutionPreset non .max value, something like this:

    CameraController(camera, ResolutionPreset.veryHigh, imageFormatGroup: ImageFormatGroup.jpeg);

    NOTE: changing ResolutionPreset causes aspect ratio changes

  6. ming-chu commented on Oct 17, 2024

    @ming-chu
    Author

    It can be solved when you set ResolutionPreset non .max value, something like this:

    CameraController(camera, ResolutionPreset.veryHigh, imageFormatGroup: ImageFormatGroup.jpeg);

    NOTE: changing ResolutionPreset causes aspect ratio changes

    @mkarapetyan-clgx Yes, I used other ResolutionPreset value as a workaround.
    But I think this is not a normal behavior to throw an exception when using .max.

  7. Brysenp commented on Oct 21, 2024

    @Brysenp

    I'm able to replicate the issue reported by @ming-chu on an iPhone 16 Pro using the following camera package version:

       camera: ^0.11.0+2
    

    Here are the relevant logs and Flutter doctor output:

    Logs
       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)
    Doctor output
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 3.24.3, on macOS 15.0.1 24A348 darwin-arm64, locale en-SG)
    [✓] 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)
    [✓] VS Code (version 1.94.1)
    [✓] Connected device (4 available)
    [✓] Network resources

    Has there been any progress on this issue? I'd be happy to provide any additional information or assist with testing if needed.

  8. ming-chu commented on Oct 21, 2024

    @ming-chu
    Author

    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

      if (self.mediaSettings.resolutionPreset == FCPPlatformResolutionPresetMax) {
        [settings setHighResolutionPhotoEnabled:YES];
      }
  9. Brysenp commented on Nov 5, 2024

    @Brysenp

    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?

  10. ming-chu commented on Nov 27, 2024

    @ming-chu
    Author

    @Brysenp

    I tested with iOS 18.0.1 (22A3370) and still have error when taking photo with camera com.apple.avfoundation.avcapturedevice.built-in_video:5

    Do you have any ideas?

    flutter: Using camera: com.apple.avfoundation.avcapturedevice.built-in_video:5
    flutter: CameraException(Error -11800, The operation could not be completed)
    
  11. jmagman commented on Dec 20, 2024

    @jmagman
    Member

    @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.

  12. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 20, 2024
  13. github-actions commented on Jan 10, 2025

    @github-actions

    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.

  14. github-actions commented on Jan 25, 2025

    @github-actions

    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 -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: crashStack traces logged to the consolee: device-specificOnly manifests on certain devicesp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions