Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] flashMode must be set to a value present in the supportedFlashModes array #74112

Closed
bhanuka96 opened this issue Jan 16, 2021 · 2 comments

Comments

@bhanuka96
Copy link

bhanuka96 commented Jan 16, 2021

My app rejected by apple because of this crash on IPad. How do I fix this issue?

plugin

camera: ^0.6.4+5

flutter doctor -v

[✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en-LK)
    • Flutter version 1.22.5 at /Users/bhanukaisuru/flutter
    • Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
    • Engine revision ae90085a84
    • Dart version 2.10.4

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/bhanukaisuru/Library/Android/sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin installed
    • Dart plugin version 201.9245
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.52.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.18.1

[✓] Connected device (2 available)
    • SM C701F (mobile)                              • b4d0901d                             • android-arm64 • Android 8.0.0 (API 26)
    • iPad Pro (12.9-inch) (4th generation) (mobile) • D4EFD850-D5FB-4A0D-89EA-9A87858BB158 • ios           • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)

• No issues found!

Crash Log

Crashed: com.google.firebase.crashlytics.ios.exception
0  FirebaseCrashlytics            0x1035e07bc FIRCLSProcessRecordAllThreads + 180
1  FirebaseCrashlytics            0x1035e0ba0 FIRCLSProcessRecordAllThreads + 1176
2  FirebaseCrashlytics            0x1035d8170 FIRCLSHandler + 48
3  FirebaseCrashlytics            0x1035d3b30 __FIRCLSExceptionRecord_block_invoke + 92
4  libdispatch.dylib              0x1b069c280 _dispatch_client_callout + 16
5  libdispatch.dylib              0x1b064bb8c _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  FirebaseCrashlytics            0x1035d32c8 FIRCLSExceptionRecord + 212
7  FirebaseCrashlytics            0x1035d35c0 FIRCLSExceptionRecordNSException + 536
8  FirebaseCrashlytics            0x1035d2ea8 FIRCLSTerminateHandler() + 400
9  libc++abi.dylib                0x1c4ec8154 std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x1c4ec80ec std::terminate() + 44
11 libobjc.A.dylib                0x1c4dccd88 _objc_terminate() + 10
12 libdispatch.dylib              0x1b069c294 _dispatch_client_callout + 36
13 libdispatch.dylib              0x1b0644dcc _dispatch_lane_serial_drain$VARIANT$mp + 612
14 libdispatch.dylib              0x1b06458a8 _dispatch_lane_invoke$VARIANT$mp + 424
15 libdispatch.dylib              0x1b064f338 _dispatch_workloop_worker_thread + 712
16 libsystem_pthread.dylib        0x1f84e75a4 _pthread_wqthread + 272
17 libsystem_pthread.dylib        0x1f84ea874 start_wqthread + 8

Full Code

class TakePicturePage extends StatefulWidget {
  final CameraDescription camera;

  TakePicturePage({@required this.camera});

  @override
  _TakePicturePageState createState() => _TakePicturePageState();
}

class _TakePicturePageState extends State<TakePicturePage> {
  CameraController _cameraController;
  Future<void> _initializeCameraControllerFuture;

  @override
  void initState() {
    super.initState();
    _cameraController = CameraController(widget.camera, ResolutionPreset.medium);
    _initializeCameraControllerFuture = _cameraController.initialize().then((value) {
      _cameraController.setFlashMode(FlashMode.off);
    });
  }

  void _takePicture(BuildContext context) async {
    try {
      await _initializeCameraControllerFuture;

      // final path = join((await getTemporaryDirectory()).path, '${DateTime.now()}.png');

      XFile xFile = await _cameraController.takePicture();

      Navigator.pop(context, xFile.path);
    } catch (e) {
      print('$e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Stack(children: <Widget>[
      FutureBuilder(
        future: _initializeCameraControllerFuture,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            return CameraPreview(_cameraController);
          } else {
            return Center(child: CircularProgressIndicator(backgroundColor: Palette.white));
          }
        },
      ),
      SafeArea(
        child: Align(
          alignment: Alignment.bottomRight,
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: FloatingActionButton(
              backgroundColor: Colors.black,
              child: Icon(Icons.camera),
              onPressed: () {
                _takePicture(context);
              },
            ),
          ),
        ),
      )
    ]);
  }

  @override
  void dispose() {
    _cameraController?.dispose();
    super.dispose();
  }
}

OnPressed Event

 final cameras = await availableCameras();
      final camera = cameras.first;
      final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => TakePicturePage(camera: camera)));
      if (result != null) {
        setState(() {
          profileImage = File(result);
        });
      }
@darshankawar
Copy link
Member

@bhanuka96
There was similar issue fixed and merged very recently, #73726 ,flutter/plugins#3411,
You may try to switch to latest master and check to see if it resolves your issue. Or you may also cherry pick the changes from the merged PR until a new camera version is available.
I am going ahead and closing this as duplicate and already fixed. If you disagree or think this is still occuring with new changes, write in comments and I'll reopen it.
Thanks.

@github-actions
Copy link

github-actions bot commented Aug 7, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants