简体   繁体   中英

React Native on iOS crashed while calling native module and try to present ViewController

When trying to present a ViewController, on native modules it's crash.

Here is the code on the native side.

@objc(SomethingManager)
class SomethingManager : NSObject {

@objc(doPresent)
func doPresent() {

  let vc = UIViewController()

  let navigationController = UINavigationController(rootViewController: vc)
  navigationController.setNavigationBarHidden(true, animated: false)


  let rootViewController = UIApplication.shared.keyWindow?.rootViewController
  rootViewController?.dismiss(animated: false, completion: nil)
  rootViewController?.present(vc, animated: true, completion: nil)
 }
}

the crash said

'Application tried to present modally an active controller <UIViewController: 0x7fb09441e620>`

I've tried to call it on main thread, without any luck

You are trying to present vc , which is already embedded in your navigationController . You should therefore be presenting navigationController and not vc .

rootViewController?.present(navigationController, animated: true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM