正在进行工作。我已经与控制器建立基本的连接,目前正在对其抽象化,以便您可以将此Cocoa Pod集成到项目中。我不想让您处理IOHIDDevices,而是希望使用真正的控制器实例和适当的通知。
这是一个提供用于与Xbox输入设备(如控制器、乐器和鼓组)简单API的CocoaPod。
现在您可以使用USB线缆设备开始了!如果您计划使用无线设备,您需要首先购买一个。
前往cocoapods.org了解更多关于它是如何工作的。这里有一个简短说明
git clone git://github.com/halo/Xbox360ControllerManager.git ~/some/where
Gemfile
source :rubygems
gem 'cocoapods'
Podfile
platform :osx
xcodeproj 'YourProject'
pod 'Xbox360ControllerManager', '0.0.1', :local => '~/some/where'
gem install bundle
bundle install
pod install
这将是应用程序代理的一个最小实现。
#import "AppDelegate.h"
#import "Xbox360Controller.h"
#import "Xbox360ControllerManager.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Start listening for device activity
[Xbox360ControllerManager sharedInstance];
// Register to the notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerAdded:) name:Xbox360ControllerAddedNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerRemoved:) name:Xbox360ControllerRemovedNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerActivity:) name:Xbox360ControllerActivityNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerUpdated:) name:Xbox360ControllerUpdatedNotification object:NULL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerAction:) name:Xbox360ControllerActionNotification object:NULL];
}
- (void) controllerAdded:(NSNotification*)notification {
NSLog(@"You added a controller: %@", [notification object]);
}
- (void) controllerRemoved:(NSNotification*)notification {
NSLog(@"You removed a controller: %@", [notification object]);
}
- (void) controllerActivity:(NSNotification*)notification {
NSLog(@"You pressed some buttons: %@", [notification object]);
}
- (void) controllerUpdated:(NSNotification*)notification {
Xbox360Controller *controller = [notification object];
NSLog(@"Controller updated: %d", controller.leftStickHorizontal);
}
- (void) controllerAction:(NSNotification*)notification {
NSLog(@"Controller action: %@", [notification object]);
}
@end
如果你对底层探索有一定的兴趣,也可以在调用 [Xbox360HIDManager sharedInstance]
之后,注册 Xbox360HIDAddedNotification
、Xbox360HIDRemovedNotification
和 Xbox360HIDActivityNotification
。这些将为你提供活动的 IOHIDDeviceRef
。
MIT 2013 funkensturm。参见 MIT-LICENSE。