NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
93 stars 47 forks source link

Taking picture from dialog not working on iOS #227

Open izub opened 4 years ago

izub commented 4 years ago

Which platform(s) does your issue occur on?

iOS 12.4.1 on iPhone 8

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Given a nativescript angular app where a custom fullscreen dialog is opened. This dialog has a button which will call takePicture on tapping it. It should open the native camera app. Instead, nothing happens while the following error is thrown in the console

Warning: attempt to present <UIImagePickerController: 0x15484c000> on <UINavigationControllerImpl: 0x1528bdc00> whose view is not in the window hierarchy
DimitarTodorov commented 4 years ago

Hi @izub Can you please share us an example or code sample where the issue can be reproduced?

alpha-nero1 commented 3 years ago

Hi, I am also getting this issue but for me it is occuring when I try and call takePicture() from within one of the BottomNavigation tabs.

It appears that the UINavigationControllerImpl that is used for the TabContentItem is somehow detatched from the window hierarchy and so the modal for taking a picture does not show.

I meddled with some of the plugin code and found that when I replaced the block at camera.ios.js:

let topMostFrame = frame.topmost();
        if (topMostFrame) {
            let viewController: UIViewController = topMostFrame.currentPage && topMostFrame.currentPage.ios;
            if (viewController) {
                while (viewController.parentViewController) {
                    // find top-most view controler
                    viewController = viewController.parentViewController;
                }

                while (viewController.presentedViewController) {
                    // find last presented modal
                    viewController = viewController.presentedViewController;
                }

                viewController.presentViewControllerAnimatedCompletion(imagePickerController, true, null);
            }
        }

with

UIApplication.sharedApplication.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(imagePickerController, true, null);

The modal worked again because the root view controller of course is part of the window hierarchy

alpha-nero1 commented 3 years ago

I would love to contribute, maybe add an option to just use the root view controller, for those of us that are trying to use this plugin inside of BottomNavigation, Please let me know what you think.

lucasumberto commented 3 years ago

I had the same problem calling takePicture in a random vue component( @alpha-nero1 solution solved the problem ), and opening it in a modal i had a different problem:

it don't throw error but the camera opens behind the modal. it seems to be related to the parent frame(component/view) of the camera, seems it's aways the root, would be nice if there is any options for we choose the parent frame for the camera open. See the screenshot what happens: -After tap on take picture option in the modal, it start to loading and the camera opens behind it, it should opens in front of its parent component.

Captura de Tela 2021-03-03 às 12 53 14