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

Taking picture from dialog not working on iOS #227

Open
izub opened this issue Oct 15, 2019 · 4 comments
Open

Taking picture from dialog not working on iOS #227

izub opened this issue Oct 15, 2019 · 4 comments

Comments

@izub
Copy link

izub commented Oct 15, 2019

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:

  • CLI: 6.1.1
  • Cross-platform modules: 6.1.1
  • Runtime(s): tns-ios: 6.1.1
  • Plugin(s): nativescript-camera: 4.5.0, nativescript-angular: 8.2.1

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
@izub izub changed the title Taking picture from dialog not working Taking picture from dialog not working on iOS Oct 15, 2019
@DimitarTodorov
Copy link
Contributor

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

@alpha-nero1
Copy link

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
Copy link

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
Copy link

lucasumberto commented Mar 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants