简体   繁体   中英

(iOS) How can I get the UIViewController from a C++ Application?

I need to use a library in my C++ project that needs to call an extern function:

SetGameViewController(UIViewController* gameViewController)

I have zero knowledge of Objective C and iOS yet. I need to get UIViewController and pass it to that function.

So this code should get the UIViewController:

UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;

I also added this import:

#if defined(OS_IPHONE)
     #import <UIKit/UIKit.h>
#endif

I get compiler errors like:

Expected unqualified-id
Unknown type name 'NSString'

I've started learning Objective C and read a few articles but couldn't get much further than that yet. So basically my question is how do I basically import and use Objective C code in C++ code so that I can get and use the UIViewController?

最简单的方法是使用扩展名“ .mm”重命名源文件-然后将其编译为Objective-C ++,这意味着您在充分利用C ++的同时仍可与Objective-C对象进行交互(计数指针)从NSObject“衍生”的东西)。

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