L'adoption de UIKeyInput protocole pour obtenir l'entrée d'un clavier Bluetooth

J'ai un Bluetooth commutateur au pied, c'est essentiellement un clavier sans fil. Une pédale envoie la touche flèche vers le haut, l'autre envoie la flèche vers le bas. Je veux être en mesure d'exécuter mon propre code dans mon iPad app quand on de la pédale est enfoncée. Le fabricant de la pédale me dit que je dois créer un UITextField, et d'adopter la UIKeyInput protocole dans le contenant UIView et l'utilisation de la beginningOfDocument et endOfDocument méthodes d'exécuter mon code. Je l'ai fait, mais peu importe ce que je fais, aucun des UIKeyInput ou UITextInput méthodes appelées. Quelqu'un peut-il me guider à travers ce, ou me diriger vers un tutoriel sur quelque chose de semblable à cela? Est-il un moyen plus facile de faire cela?

Merci pour votre aide.

Voici mon .h:

#import <UIKit/UIKit.h>

@interface Pedal_ProtocolViewController : UIViewController <UIKeyInput, UITextInput>{
UITextField *myTextField;
}
@property (nonatomic, retain) IBOutlet UITextField *myTextField;
@end

Et voici mon .m:

#import "Pedal_ProtocolViewController.h"
@implementation Pedal_ProtocolViewController
@synthesize myTextField;
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
//Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
//Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
//Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
[myTextField canBecomeFirstResponder];
[myTextField becomeFirstResponder];
}
- (void)viewDidUnload
{
[super viewDidUnload];
//Release any retained subviews of the main view.
//e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//Return YES for supported orientations
return YES;
}
#pragma mark -
#pragma mark UIKeyInput Protocol Methods
- (BOOL)hasText {
return NO;
}
- (void)insertText:(NSString *)theText {
}
- (void)deleteBackward {
}
- (BOOL)canBecomeFirstResponder {
return YES; 
}
#pragma mark -
#pragma mark UITextInput Protocol Methods
- (NSString *)textInRange:(UITextRange *)range {
return @"";
}
- (void)replaceRange:(UITextRange *)range withText:(NSString *)text {
}
- (void) setSelectedTextRange: (UITextRange *) range {
}
- (UITextRange *) markedTextRange {
return nil;
}
- (NSDictionary *) markedTextStyle {
return nil;
}
- (void) setMarkedTextStyle: (NSDictionary *) style {
}
- (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange {
}
- (void) unmarkText {
}
- (UITextPosition *) endOfDocument {
//DOWN KEY
NSLog(@"Down");
return nil;
}
- (UITextPosition *) beginningOfDocument {
//UP KEY
NSLog(@"UP");
return nil;
}
- (UITextRange *)textRangeFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition{
return nil;
}
- (UITextPosition *)positionFromPosition:(UITextPosition *)position offset:(NSInteger)offset{
return nil;
}
- (UITextPosition *)positionFromPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction offset:(NSInteger)offset {
return nil;
}
- (NSComparisonResult) comparePosition: (UITextPosition *)position toPosition: (UITextPosition *)other {
return NSOrderedSame;
}
- (NSInteger) offsetFromPosition: (UITextPosition *)from toPosition: (UITextPosition *)toPosition {
return 0;
}
- (void) setInputDelegate: (id <UITextInputDelegate>) delegate {
}
- (id <UITextInputDelegate>) inputDelegate {
return nil;
}
- (id <UITextInputTokenizer>) tokenizer {
return nil;
}
- (UITextPosition *)positionWithinRange:(UITextRange *)range farthestInDirection:(UITextLayoutDirection)direction {
return nil;
}
- (UITextRange *) characterRangeByExtendingPosition: (UITextPosition *) position inDirection: (UITextLayoutDirection) direction {
return nil;
}
- (UITextWritingDirection) baseWritingDirectionForPosition: (UITextPosition *)position inDirection: (UITextStorageDirection)direction {
return 0;
}
- (void) setBaseWritingDirection: (UITextWritingDirection)writingDirection forRange:(UITextRange *)range {
}
- (CGRect) firstRectForRange: (UITextRange *) range {
return CGRectZero;
}
- (CGRect) caretRectForPosition: (UITextPosition *) position  {
return CGRectZero;
}
- (UITextPosition *) closestPositionToPoint: (CGPoint)point {
return nil;
}
- (UITextPosition *) closestPositionToPoint: (CGPoint)point withinRange: (UITextRange *) range {
return nil;
}
- (UITextRange *) characterRangeAtPoint: (CGPoint)point {
return nil;
}
- (UITextRange *) selectedTextRange {
return [[UITextRange alloc]init];
}
@end
J'ai le même problème aujourd'hui, n'avez-vous jamais comprendre cela?
Il y a quelques tidbits utiles à avoir dans le DCIntrospect projet sur Github. Ces gars-utilisez des sélection soignée de suivi de distinguer entre le haut, le bas, la gauche, la droite, et tous les quatre, soit avec la touche maj et option. Tout, une sacrément impressionnant effort, j'ai pensé.

OriginalL'auteur fredwardo | 2011-09-14