pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.15k stars 1.47k forks source link

Open selfie camera IOS #1873

Open gjae opened 10 months ago

gjae commented 10 months ago

I'm working with face recognition, therefore I need open selfie camera, in Android works fine but Ios open back camera instead of selfie camera. How can I open selfie camera as default?.

My Js code:

const userMedia = useUserMedia({
      constraints: {
        audio: false,
        video: {
          facingMode: "user",
          width: { max: 1024 },
          height: { max: 1024 },
          aspectRatio: { ideal: 1 },
        },
      },
    });

      try {
        const mediaStream = await this.userMedia.start();
        if (mediaStream === undefined) throw Error();

        this.idface.countdown = 3;
        this.idface.interval_id = window.setInterval(() => {
          if (this.idface.countdown > 0) {
            this.idface.countdown--;
            return;
          }

          window.clearInterval(this.idface.interval_id);
          this.idface.interval_id = undefined;

          this.identifyFace();
          this.idface.active = false;
          this.userMedia.stop();
        }, 1000);
      } catch (e) {
        this.idface.active = false;
        swalError("No se tiene permiso para acceder a la cámara");
      }
github-actions[bot] commented 10 months ago

👋 @gjae

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

vijayunified commented 4 months ago

Yes, I'm also facing the same issue. In Android, I'm able to open and capture images using front and back cameras but in IOS I'm not able to open the front camera. can anyone help me with it,

Here is my code.

InAppWebView( initialUrlRequest: URLRequest(url: WebUri(widget.webUrl.toString())), initialSettings: InAppWebViewSettings( allowFileAccess: true, allowContentAccess: true, iframeAllow: "camera; microphone", iframeAllowFullscreen: true, mediaPlaybackRequiresUserGesture: false, useShouldOverrideUrlLoading: true, useHybridComposition:true, allowsInlineMediaPlayback: true, javaScriptEnabled: true, hardwareAcceleration: true), shouldOverrideUrlLoading: (controller, navAction) async { return NavigationActionPolicy.ALLOW; }, onReceivedError: (controller, request, error){ AppLog.logPrint("RECEIVED ERROR: ${error}"); }, onPermissionRequest: (controller, request) async { print(request); return PermissionResponse( resources: request.resources, action: PermissionResponseAction.GRANT); }, onWebViewCreated: (InAppWebViewController inAppWebViewController) { _controller.complete(inAppWebViewController); }, onLoadStart: (InAppWebViewController, url) { setState(() { this.url = url?.toString() ?? ''; }); }, onReceivedServerTrustAuthRequest: (_, challenge) async { return ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED); }, onCameraCaptureStateChanged: (inAppWebViewController, oldState, newState) async { var state= await inAppWebViewController.getCameraCaptureState(); return inAppWebViewController.setCameraCaptureState( state:state!); }, onConsoleMessage: (InAppWebViewController, consoleMessage) { AppLog.logPrint(consoleMessage); /*if (controller.status.isSuccess == 1) { Get.offAll(const BottomNav(setIndex: 0)); }*/ // it will print: {message: {"bar":"bar_value","baz":"baz_value"}, messageLevel: 1} }, onPageCommitVisible: (InAppWebViewController, url) async { InAppWebViewController.canGoBack(); }, onProgressChanged: (InAppWebViewController, progress) { setState(() { this.progress = progress / 100; }); }, shouldInterceptAjaxRequest: (InAppWebViewController controller, AjaxRequest ajaxRequest) async { print(ajaxRequest.url); return ajaxRequest; }, onAjaxReadyStateChange: (InAppWebViewController _controller, AjaxRequest ajaxRequest) async { AppLog.logPrint(ajaxRequest.status); return AjaxRequestAction.PROCEED; }, onAjaxProgress: (InAppWebViewController _controller, AjaxRequest ajaxRequest) async { AppLog.logPrint(ajaxRequest.status); return AjaxRequestAction.PROCEED; }, onLoadStop: (InAppWebViewController, url) async { if (url.toString() == ApiConst.kycSuccessUrlDev) { await PreferenceUtils.setString( AppConstants.KYC_STATUS, KycStatus.kycSuccessful); //Get.offAll(const BottomNav(setIndex: 0)); Get.to(const KYCSuccessScreen()); //ApiRepo.showToast("KYC Completed Successfully", isForError: false); } //InAppWebViewController.canGoBack(); }, androidOnPermissionRequest: (InAppWebViewController controller, String origin, List<String> resources) async { return PermissionRequestResponse( resources: resources, action: PermissionRequestResponseAction.GRANT); }),