更新时间:2023-12-03 23:40:52
我使用以下main.m文件进行此操作:
I have this working with the following main.m file:
#import <AppKit/AppKit.h>
#import <GameController/GameController.h>
@interface AppDelegate : NSObject<NSApplicationDelegate> @end
@implementation AppDelegate
- (void) applicationDidFinishLaunching: (NSNotification*) notification {
[NSApp stop: nil]; // Allows [app run] to return
}
@end
int main() {
NSApplication* app = [NSApplication sharedApplication];
[app setActivationPolicy: NSApplicationActivationPolicyRegular];
[app setDelegate: [[AppDelegate alloc] init]];
[app run];
// 1 with a DualShock 4 plugged in
printf("controllers %lu\n", [[GCController controllers] count]);
// Do stuff here
return 0;
}
编译为: clang -framework AppKit -framework GameController main.m
我不知道为什么,但是我需要在构建输出目录中有一个Info.plist文件.没有它,controllers数组将不会被填充.这是我的整个文件:
I have no idea why, but I need an Info.plist file in the build output directory. Without it, the controllers array doesn't get populated. This is my entire file:
<dict>
<key>CFBundleIdentifier</key>
<string>your.bundle.id</string>
</dict>
我不确定提供Info.plist可能有什么含义,但是如果存在,我可以像往常一样运行a.out可执行文件,并得到我的控制器数组.
I'm not sure what implications supplying an Info.plist might have, but if it's there, I can run the a.out executable as normal and I get my controllers array.