首页 > 解决方案 > 在 React Native Library 中,我如何获取 ios 当前的 UIViewController

问题描述

android中的react native库可以使用“getCurrentActivity()”来替换“this”

final Activity activity = getCurrentActivity();

而在ios中如何使用替换“self”来获取当前的UIViewController

标签: react-nativereact-native-ios

解决方案


对于“当前 UIViewController”,您很可能需要文件RCTPresentedViewController中的函数RCTUtils.h

#import <React/RCTUtils.h>

// ...
  UIViewController* vc = RCTPresentedViewController();
// ...

注意:非常旧的RN版本没有这个API,但是可以很容易地手动实现,实现很容易:RCTUtils.m


推荐阅读