Is it possible to access camera from inappbrowser/webview on iOSCordova Embedded webview not responding navigator.camera is undefinedNo permission for camera access in Cordova webview for Android lollipopcordova inappbrowser iOS issuesCordova: Camera PLugin not workinggetUserMedia() in apache cordova? Any alternative?Input type=“file” on Cordova 7, WebView, Android 7.1 only opens file browser directly, cannot choose cameraIOS 11.2 Cordova Inappbrowser adds a grey block on orientation changeDoes Android older version support Webrtc video chat in Android appTriggering Cordova Camera Plugin w/ ReactjsHow to fix “stretched view” of camera stream on some devices (getUserMedia)

Meta programming: Declare a new struct on the fly

Perfect riffle shuffles

Simulating a probability of 1 of 2^N with less than N random bits

Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)

Simple image editor tool to draw a simple box/rectangle in an existing image

Visiting the UK as unmarried couple

Can somebody explain Brexit in a few child-proof sentences?

Stereotypical names

How can I successfully establish a nationwide combat training program for a large country?

Indicating multiple different modes of speech (fantasy language or telepathy)

Latex for-and in equation

Simple recursive Sudoku solver

What is the opposite of 'gravitas'?

Books on the History of math research at European universities

I2C signal and power over long range (10meter cable)

Is infinity mathematically observable?

A workplace installs custom certificates on personal devices, can this be used to decrypt HTTPS traffic?

Giant Toughroad SLR 2 for 200 miles in two days, will it make it?

Should a half Jewish man be discouraged from marrying a Jewess?

Who must act to prevent Brexit on March 29th?

How will losing mobility of one hand affect my career as a programmer?

My boss asked me to take a one-day class, then signs it up as a day off

Bob has never been a M before

Proof of Lemma: Every integer can be written as a product of primes



Is it possible to access camera from inappbrowser/webview on iOS


Cordova Embedded webview not responding navigator.camera is undefinedNo permission for camera access in Cordova webview for Android lollipopcordova inappbrowser iOS issuesCordova: Camera PLugin not workinggetUserMedia() in apache cordova? Any alternative?Input type=“file” on Cordova 7, WebView, Android 7.1 only opens file browser directly, cannot choose cameraIOS 11.2 Cordova Inappbrowser adds a grey block on orientation changeDoes Android older version support Webrtc video chat in Android appTriggering Cordova Camera Plugin w/ ReactjsHow to fix “stretched view” of camera stream on some devices (getUserMedia)













0















I have tried every possible way to access camera on webview on cordova.



It work on android, but doesn't work on iOS.



Can someone explain how to implement access camera feature via cordova webview on iOS thanks.




Inappbrowser side (Angular)




if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) 
navigator.mediaDevices
.getUserMedia( video: facingMode: 'environment' )
.then(stream =>
// this.videoDom.srcObject = stream;
this.videoDom.srcObject = stream;
this.videoDom.setAttribute('playsinline', 'true');
this.videoDom.play();

this.stream = stream.getTracks();

requestAnimationFrame(tick);
)




Cordova side




I have install cordova-plugin-camera and add permission in config.xml on ios platform.










share|improve this question
























  • Yes image picker and camera works for iOS in webviews. You may have to see html or javascript support for iOS, or consult any web frontend developer

    – Amber K
    Mar 7 at 10:32











  • @AmberK can you show me some code for explanation. right now on iOS my cordova inappbrowser cannot access camera.

    – Borishi
    Mar 7 at 10:44











  • Can you give us code you used for Android please ?

    – Enzo BLANCHON
    Mar 7 at 10:58











  • @EnzoBLANCHON I have update camera access function, please guide me.

    – Borishi
    Mar 7 at 11:08















0















I have tried every possible way to access camera on webview on cordova.



It work on android, but doesn't work on iOS.



Can someone explain how to implement access camera feature via cordova webview on iOS thanks.




Inappbrowser side (Angular)




if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) 
navigator.mediaDevices
.getUserMedia( video: facingMode: 'environment' )
.then(stream =>
// this.videoDom.srcObject = stream;
this.videoDom.srcObject = stream;
this.videoDom.setAttribute('playsinline', 'true');
this.videoDom.play();

this.stream = stream.getTracks();

requestAnimationFrame(tick);
)




Cordova side




I have install cordova-plugin-camera and add permission in config.xml on ios platform.










share|improve this question
























  • Yes image picker and camera works for iOS in webviews. You may have to see html or javascript support for iOS, or consult any web frontend developer

    – Amber K
    Mar 7 at 10:32











  • @AmberK can you show me some code for explanation. right now on iOS my cordova inappbrowser cannot access camera.

    – Borishi
    Mar 7 at 10:44











  • Can you give us code you used for Android please ?

    – Enzo BLANCHON
    Mar 7 at 10:58











  • @EnzoBLANCHON I have update camera access function, please guide me.

    – Borishi
    Mar 7 at 11:08













0












0








0








I have tried every possible way to access camera on webview on cordova.



It work on android, but doesn't work on iOS.



Can someone explain how to implement access camera feature via cordova webview on iOS thanks.




Inappbrowser side (Angular)




if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) 
navigator.mediaDevices
.getUserMedia( video: facingMode: 'environment' )
.then(stream =>
// this.videoDom.srcObject = stream;
this.videoDom.srcObject = stream;
this.videoDom.setAttribute('playsinline', 'true');
this.videoDom.play();

this.stream = stream.getTracks();

requestAnimationFrame(tick);
)




Cordova side




I have install cordova-plugin-camera and add permission in config.xml on ios platform.










share|improve this question
















I have tried every possible way to access camera on webview on cordova.



It work on android, but doesn't work on iOS.



Can someone explain how to implement access camera feature via cordova webview on iOS thanks.




Inappbrowser side (Angular)




if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) 
navigator.mediaDevices
.getUserMedia( video: facingMode: 'environment' )
.then(stream =>
// this.videoDom.srcObject = stream;
this.videoDom.srcObject = stream;
this.videoDom.setAttribute('playsinline', 'true');
this.videoDom.play();

this.stream = stream.getTracks();

requestAnimationFrame(tick);
)




Cordova side




I have install cordova-plugin-camera and add permission in config.xml on ios platform.







ios cordova






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 11:07







Borishi

















asked Mar 7 at 10:19









BorishiBorishi

107




107












  • Yes image picker and camera works for iOS in webviews. You may have to see html or javascript support for iOS, or consult any web frontend developer

    – Amber K
    Mar 7 at 10:32











  • @AmberK can you show me some code for explanation. right now on iOS my cordova inappbrowser cannot access camera.

    – Borishi
    Mar 7 at 10:44











  • Can you give us code you used for Android please ?

    – Enzo BLANCHON
    Mar 7 at 10:58











  • @EnzoBLANCHON I have update camera access function, please guide me.

    – Borishi
    Mar 7 at 11:08

















  • Yes image picker and camera works for iOS in webviews. You may have to see html or javascript support for iOS, or consult any web frontend developer

    – Amber K
    Mar 7 at 10:32











  • @AmberK can you show me some code for explanation. right now on iOS my cordova inappbrowser cannot access camera.

    – Borishi
    Mar 7 at 10:44











  • Can you give us code you used for Android please ?

    – Enzo BLANCHON
    Mar 7 at 10:58











  • @EnzoBLANCHON I have update camera access function, please guide me.

    – Borishi
    Mar 7 at 11:08
















Yes image picker and camera works for iOS in webviews. You may have to see html or javascript support for iOS, or consult any web frontend developer

– Amber K
Mar 7 at 10:32





Yes image picker and camera works for iOS in webviews. You may have to see html or javascript support for iOS, or consult any web frontend developer

– Amber K
Mar 7 at 10:32













@AmberK can you show me some code for explanation. right now on iOS my cordova inappbrowser cannot access camera.

– Borishi
Mar 7 at 10:44





@AmberK can you show me some code for explanation. right now on iOS my cordova inappbrowser cannot access camera.

– Borishi
Mar 7 at 10:44













Can you give us code you used for Android please ?

– Enzo BLANCHON
Mar 7 at 10:58





Can you give us code you used for Android please ?

– Enzo BLANCHON
Mar 7 at 10:58













@EnzoBLANCHON I have update camera access function, please guide me.

– Borishi
Mar 7 at 11:08





@EnzoBLANCHON I have update camera access function, please guide me.

– Borishi
Mar 7 at 11:08












3 Answers
3






active

oldest

votes


















0














On iOS11/12 navigator.getMediaDevices is not available for WKWebView and UIWebView. It is only available for Safari. (https://forums.developer.apple.com/thread/88052)




WebRTC is only supported in Safari. No WKWebView, not even
SFSafariViewController.




You can try to use this plugin normally should solve your problem: https://github.com/phonegap/phonegap-plugin-media-stream



navigator.mediaDevices.getUserMedia(
'audio': true,
'video':
facingMode: 'environment'

).then(function(mediaStream)
// Do what you want with






share|improve this answer























  • This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

    – DaveAlden
    Mar 7 at 11:52






  • 1





    @EnzoBLANCHON your example repo work well, thanks.

    – Borishi
    Mar 11 at 9:22


















0














I've thought of a hacky way you can make this work on iOS by using the new postMessage API feature of cordova-plugin-inappbrowser which enables you to send messages from pages loaded into the Inappbrowser Webview back to the main Cordova app Webview.
This is not present in the latest release on npm (3.0.0), so you'd need to install the master version (3.1.0-dev) directly from Github:



cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser


In the page loaded into the inappbrowser, you can then post messages back to the Cordova app webview:



function openCamera()
postMessage(
action: "camera"
);


function postMessage(message)
if(!webkit.messageHandlers.cordova_iab) throw "Cordova IAB postMessage API not found!";
webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));


<button onclick="openCamera()">Open camera<button>


On the Cordova app side, you can then listen for that message and respond to it:



var iab = cordova.InAppBrowser.open(myUrl, '_blank', iabOpts);

iab.addEventListener('message', function (e)
if(e.data.action === 'camera')
openCamera();

);

function openCamera()
var animationDelay = 500; // delay to wait for camera window animation
navigator.camera.getPicture(function()
log("successfully opened camera");
if (device.platform === "iOS")
// unhide IAB
iab.show();

, function(cameraError)
error("error opening camera: "+cameraError);
if (device.platform === "iOS")
iab.show();

);
if (device.platform === "iOS")
// hide IAB so camera window is in view
setTimeout(iab.hide, animationDelay);




This allows you to directly call cordova-plugin-camera from within the inappbrowser.



However it is hacky because on iOS, by default the camera window will appear below the inappbrowser window in the view hierarchy and hence not be visible.
My hack is to hide the inappbrowser window upon opening the camera, which causes the camera window to be at the top of the visible view hierarcy and be displayed.
However, upon dismissing the camera window, the Cordova app window will briefly be displayed while the inappbrowser window is being animated to show again.



I created a test case example in my inappbrowser test app repo: https://github.com/dpa99c/cordova-plugin-inappbrowser-test/tree/camera



You can try it like this:



git clone -b camera https://github.com/dpa99c/cordova-plugin-inappbrowser-test
cd cordova-plugin-inappbrowser-test
cordova platform add ios
cordova run ios





share|improve this answer























  • thanks for explanation.

    – Borishi
    Mar 11 at 9:23



















0














There is a simpler way, just use input type file



This shows the camera for taking a picture



<input type="file" accept="image/*" capture>



This for recording video



<input type="file" accept="video/*" capture>



This will prompt to take a picture or video, choose from the photo library or explore files



<input type="file">



There are a few other combinations. But it probably doesn't work on Android






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55041319%2fis-it-possible-to-access-camera-from-inappbrowser-webview-on-ios%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    On iOS11/12 navigator.getMediaDevices is not available for WKWebView and UIWebView. It is only available for Safari. (https://forums.developer.apple.com/thread/88052)




    WebRTC is only supported in Safari. No WKWebView, not even
    SFSafariViewController.




    You can try to use this plugin normally should solve your problem: https://github.com/phonegap/phonegap-plugin-media-stream



    navigator.mediaDevices.getUserMedia(
    'audio': true,
    'video':
    facingMode: 'environment'

    ).then(function(mediaStream)
    // Do what you want with






    share|improve this answer























    • This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

      – DaveAlden
      Mar 7 at 11:52






    • 1





      @EnzoBLANCHON your example repo work well, thanks.

      – Borishi
      Mar 11 at 9:22















    0














    On iOS11/12 navigator.getMediaDevices is not available for WKWebView and UIWebView. It is only available for Safari. (https://forums.developer.apple.com/thread/88052)




    WebRTC is only supported in Safari. No WKWebView, not even
    SFSafariViewController.




    You can try to use this plugin normally should solve your problem: https://github.com/phonegap/phonegap-plugin-media-stream



    navigator.mediaDevices.getUserMedia(
    'audio': true,
    'video':
    facingMode: 'environment'

    ).then(function(mediaStream)
    // Do what you want with






    share|improve this answer























    • This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

      – DaveAlden
      Mar 7 at 11:52






    • 1





      @EnzoBLANCHON your example repo work well, thanks.

      – Borishi
      Mar 11 at 9:22













    0












    0








    0







    On iOS11/12 navigator.getMediaDevices is not available for WKWebView and UIWebView. It is only available for Safari. (https://forums.developer.apple.com/thread/88052)




    WebRTC is only supported in Safari. No WKWebView, not even
    SFSafariViewController.




    You can try to use this plugin normally should solve your problem: https://github.com/phonegap/phonegap-plugin-media-stream



    navigator.mediaDevices.getUserMedia(
    'audio': true,
    'video':
    facingMode: 'environment'

    ).then(function(mediaStream)
    // Do what you want with






    share|improve this answer













    On iOS11/12 navigator.getMediaDevices is not available for WKWebView and UIWebView. It is only available for Safari. (https://forums.developer.apple.com/thread/88052)




    WebRTC is only supported in Safari. No WKWebView, not even
    SFSafariViewController.




    You can try to use this plugin normally should solve your problem: https://github.com/phonegap/phonegap-plugin-media-stream



    navigator.mediaDevices.getUserMedia(
    'audio': true,
    'video':
    facingMode: 'environment'

    ).then(function(mediaStream)
    // Do what you want with







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 7 at 11:12









    Enzo BLANCHONEnzo BLANCHON

    731317




    731317












    • This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

      – DaveAlden
      Mar 7 at 11:52






    • 1





      @EnzoBLANCHON your example repo work well, thanks.

      – Borishi
      Mar 11 at 9:22

















    • This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

      – DaveAlden
      Mar 7 at 11:52






    • 1





      @EnzoBLANCHON your example repo work well, thanks.

      – Borishi
      Mar 11 at 9:22
















    This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

    – DaveAlden
    Mar 7 at 11:52





    This plugin will add the functionality to the main Cordova app webview but not the Inappbrowser Webview, so the navigator.mediaDevices namespace will not be defined in pages loaded into the inappbrowser.

    – DaveAlden
    Mar 7 at 11:52




    1




    1





    @EnzoBLANCHON your example repo work well, thanks.

    – Borishi
    Mar 11 at 9:22





    @EnzoBLANCHON your example repo work well, thanks.

    – Borishi
    Mar 11 at 9:22













    0














    I've thought of a hacky way you can make this work on iOS by using the new postMessage API feature of cordova-plugin-inappbrowser which enables you to send messages from pages loaded into the Inappbrowser Webview back to the main Cordova app Webview.
    This is not present in the latest release on npm (3.0.0), so you'd need to install the master version (3.1.0-dev) directly from Github:



    cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser


    In the page loaded into the inappbrowser, you can then post messages back to the Cordova app webview:



    function openCamera()
    postMessage(
    action: "camera"
    );


    function postMessage(message)
    if(!webkit.messageHandlers.cordova_iab) throw "Cordova IAB postMessage API not found!";
    webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));


    <button onclick="openCamera()">Open camera<button>


    On the Cordova app side, you can then listen for that message and respond to it:



    var iab = cordova.InAppBrowser.open(myUrl, '_blank', iabOpts);

    iab.addEventListener('message', function (e)
    if(e.data.action === 'camera')
    openCamera();

    );

    function openCamera()
    var animationDelay = 500; // delay to wait for camera window animation
    navigator.camera.getPicture(function()
    log("successfully opened camera");
    if (device.platform === "iOS")
    // unhide IAB
    iab.show();

    , function(cameraError)
    error("error opening camera: "+cameraError);
    if (device.platform === "iOS")
    iab.show();

    );
    if (device.platform === "iOS")
    // hide IAB so camera window is in view
    setTimeout(iab.hide, animationDelay);




    This allows you to directly call cordova-plugin-camera from within the inappbrowser.



    However it is hacky because on iOS, by default the camera window will appear below the inappbrowser window in the view hierarchy and hence not be visible.
    My hack is to hide the inappbrowser window upon opening the camera, which causes the camera window to be at the top of the visible view hierarcy and be displayed.
    However, upon dismissing the camera window, the Cordova app window will briefly be displayed while the inappbrowser window is being animated to show again.



    I created a test case example in my inappbrowser test app repo: https://github.com/dpa99c/cordova-plugin-inappbrowser-test/tree/camera



    You can try it like this:



    git clone -b camera https://github.com/dpa99c/cordova-plugin-inappbrowser-test
    cd cordova-plugin-inappbrowser-test
    cordova platform add ios
    cordova run ios





    share|improve this answer























    • thanks for explanation.

      – Borishi
      Mar 11 at 9:23
















    0














    I've thought of a hacky way you can make this work on iOS by using the new postMessage API feature of cordova-plugin-inappbrowser which enables you to send messages from pages loaded into the Inappbrowser Webview back to the main Cordova app Webview.
    This is not present in the latest release on npm (3.0.0), so you'd need to install the master version (3.1.0-dev) directly from Github:



    cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser


    In the page loaded into the inappbrowser, you can then post messages back to the Cordova app webview:



    function openCamera()
    postMessage(
    action: "camera"
    );


    function postMessage(message)
    if(!webkit.messageHandlers.cordova_iab) throw "Cordova IAB postMessage API not found!";
    webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));


    <button onclick="openCamera()">Open camera<button>


    On the Cordova app side, you can then listen for that message and respond to it:



    var iab = cordova.InAppBrowser.open(myUrl, '_blank', iabOpts);

    iab.addEventListener('message', function (e)
    if(e.data.action === 'camera')
    openCamera();

    );

    function openCamera()
    var animationDelay = 500; // delay to wait for camera window animation
    navigator.camera.getPicture(function()
    log("successfully opened camera");
    if (device.platform === "iOS")
    // unhide IAB
    iab.show();

    , function(cameraError)
    error("error opening camera: "+cameraError);
    if (device.platform === "iOS")
    iab.show();

    );
    if (device.platform === "iOS")
    // hide IAB so camera window is in view
    setTimeout(iab.hide, animationDelay);




    This allows you to directly call cordova-plugin-camera from within the inappbrowser.



    However it is hacky because on iOS, by default the camera window will appear below the inappbrowser window in the view hierarchy and hence not be visible.
    My hack is to hide the inappbrowser window upon opening the camera, which causes the camera window to be at the top of the visible view hierarcy and be displayed.
    However, upon dismissing the camera window, the Cordova app window will briefly be displayed while the inappbrowser window is being animated to show again.



    I created a test case example in my inappbrowser test app repo: https://github.com/dpa99c/cordova-plugin-inappbrowser-test/tree/camera



    You can try it like this:



    git clone -b camera https://github.com/dpa99c/cordova-plugin-inappbrowser-test
    cd cordova-plugin-inappbrowser-test
    cordova platform add ios
    cordova run ios





    share|improve this answer























    • thanks for explanation.

      – Borishi
      Mar 11 at 9:23














    0












    0








    0







    I've thought of a hacky way you can make this work on iOS by using the new postMessage API feature of cordova-plugin-inappbrowser which enables you to send messages from pages loaded into the Inappbrowser Webview back to the main Cordova app Webview.
    This is not present in the latest release on npm (3.0.0), so you'd need to install the master version (3.1.0-dev) directly from Github:



    cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser


    In the page loaded into the inappbrowser, you can then post messages back to the Cordova app webview:



    function openCamera()
    postMessage(
    action: "camera"
    );


    function postMessage(message)
    if(!webkit.messageHandlers.cordova_iab) throw "Cordova IAB postMessage API not found!";
    webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));


    <button onclick="openCamera()">Open camera<button>


    On the Cordova app side, you can then listen for that message and respond to it:



    var iab = cordova.InAppBrowser.open(myUrl, '_blank', iabOpts);

    iab.addEventListener('message', function (e)
    if(e.data.action === 'camera')
    openCamera();

    );

    function openCamera()
    var animationDelay = 500; // delay to wait for camera window animation
    navigator.camera.getPicture(function()
    log("successfully opened camera");
    if (device.platform === "iOS")
    // unhide IAB
    iab.show();

    , function(cameraError)
    error("error opening camera: "+cameraError);
    if (device.platform === "iOS")
    iab.show();

    );
    if (device.platform === "iOS")
    // hide IAB so camera window is in view
    setTimeout(iab.hide, animationDelay);




    This allows you to directly call cordova-plugin-camera from within the inappbrowser.



    However it is hacky because on iOS, by default the camera window will appear below the inappbrowser window in the view hierarchy and hence not be visible.
    My hack is to hide the inappbrowser window upon opening the camera, which causes the camera window to be at the top of the visible view hierarcy and be displayed.
    However, upon dismissing the camera window, the Cordova app window will briefly be displayed while the inappbrowser window is being animated to show again.



    I created a test case example in my inappbrowser test app repo: https://github.com/dpa99c/cordova-plugin-inappbrowser-test/tree/camera



    You can try it like this:



    git clone -b camera https://github.com/dpa99c/cordova-plugin-inappbrowser-test
    cd cordova-plugin-inappbrowser-test
    cordova platform add ios
    cordova run ios





    share|improve this answer













    I've thought of a hacky way you can make this work on iOS by using the new postMessage API feature of cordova-plugin-inappbrowser which enables you to send messages from pages loaded into the Inappbrowser Webview back to the main Cordova app Webview.
    This is not present in the latest release on npm (3.0.0), so you'd need to install the master version (3.1.0-dev) directly from Github:



    cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser


    In the page loaded into the inappbrowser, you can then post messages back to the Cordova app webview:



    function openCamera()
    postMessage(
    action: "camera"
    );


    function postMessage(message)
    if(!webkit.messageHandlers.cordova_iab) throw "Cordova IAB postMessage API not found!";
    webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));


    <button onclick="openCamera()">Open camera<button>


    On the Cordova app side, you can then listen for that message and respond to it:



    var iab = cordova.InAppBrowser.open(myUrl, '_blank', iabOpts);

    iab.addEventListener('message', function (e)
    if(e.data.action === 'camera')
    openCamera();

    );

    function openCamera()
    var animationDelay = 500; // delay to wait for camera window animation
    navigator.camera.getPicture(function()
    log("successfully opened camera");
    if (device.platform === "iOS")
    // unhide IAB
    iab.show();

    , function(cameraError)
    error("error opening camera: "+cameraError);
    if (device.platform === "iOS")
    iab.show();

    );
    if (device.platform === "iOS")
    // hide IAB so camera window is in view
    setTimeout(iab.hide, animationDelay);




    This allows you to directly call cordova-plugin-camera from within the inappbrowser.



    However it is hacky because on iOS, by default the camera window will appear below the inappbrowser window in the view hierarchy and hence not be visible.
    My hack is to hide the inappbrowser window upon opening the camera, which causes the camera window to be at the top of the visible view hierarcy and be displayed.
    However, upon dismissing the camera window, the Cordova app window will briefly be displayed while the inappbrowser window is being animated to show again.



    I created a test case example in my inappbrowser test app repo: https://github.com/dpa99c/cordova-plugin-inappbrowser-test/tree/camera



    You can try it like this:



    git clone -b camera https://github.com/dpa99c/cordova-plugin-inappbrowser-test
    cd cordova-plugin-inappbrowser-test
    cordova platform add ios
    cordova run ios






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 7 at 12:06









    DaveAldenDaveAlden

    21.3k956100




    21.3k956100












    • thanks for explanation.

      – Borishi
      Mar 11 at 9:23


















    • thanks for explanation.

      – Borishi
      Mar 11 at 9:23

















    thanks for explanation.

    – Borishi
    Mar 11 at 9:23






    thanks for explanation.

    – Borishi
    Mar 11 at 9:23












    0














    There is a simpler way, just use input type file



    This shows the camera for taking a picture



    <input type="file" accept="image/*" capture>



    This for recording video



    <input type="file" accept="video/*" capture>



    This will prompt to take a picture or video, choose from the photo library or explore files



    <input type="file">



    There are a few other combinations. But it probably doesn't work on Android






    share|improve this answer



























      0














      There is a simpler way, just use input type file



      This shows the camera for taking a picture



      <input type="file" accept="image/*" capture>



      This for recording video



      <input type="file" accept="video/*" capture>



      This will prompt to take a picture or video, choose from the photo library or explore files



      <input type="file">



      There are a few other combinations. But it probably doesn't work on Android






      share|improve this answer

























        0












        0








        0







        There is a simpler way, just use input type file



        This shows the camera for taking a picture



        <input type="file" accept="image/*" capture>



        This for recording video



        <input type="file" accept="video/*" capture>



        This will prompt to take a picture or video, choose from the photo library or explore files



        <input type="file">



        There are a few other combinations. But it probably doesn't work on Android






        share|improve this answer













        There is a simpler way, just use input type file



        This shows the camera for taking a picture



        <input type="file" accept="image/*" capture>



        This for recording video



        <input type="file" accept="video/*" capture>



        This will prompt to take a picture or video, choose from the photo library or explore files



        <input type="file">



        There are a few other combinations. But it probably doesn't work on Android







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 12 at 13:32









        jcesarmobilejcesarmobile

        36.9k781126




        36.9k781126



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55041319%2fis-it-possible-to-access-camera-from-inappbrowser-webview-on-ios%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко