Android中的反应本机库可以使用“ getCurrentActivity()”替换“ this”
final Activity activity = getCurrentActivity();
然后在ios中如何使用“自我”替换当前的UIViewController
答案 0 :(得分:0)
在iOS上-除非您使用wix的react本机导航-通常在AppDelegate中仅实例化一个UIViewController
。
第一个问题:为什么需要您的应用程序UIViewController?
如果您真的需要访问它,这里是一个建议:UIApplication.sharedApplication().window.rootViewController
(此代码可能不适用于复杂的本机设置,但在简单情况下,它应该为您的应用提供ViewController)
答案 1 :(得分:0)
对于“当前UIViewController”,您很可能需要RCTPresentedViewController
文件中的RCTUtils.h
函数:
#import <React/RCTUtils.h>
// ...
UIViewController* vc = RCTPresentedViewcontroller();
// ...
注意:非常老的RN版本没有此API,但是可以很容易地手动实现,实现起来也很容易:RCTUtils.m