EAAccessory Notification problem
- by Deepak
Hi,
I am using a POS device for card swipe. its working good. i have used following codes.
(id) init
{
self = [super init];
if (self != nil)
{
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
EAAccessoryManager *accessoryMamaner = [EAAccessoryManager sharedAccessoryManager];
[accessoryMamaner registerForLocalNotifications];
[notificationCenter addObserver: self selector: @selector (accessoryDidConnect:) name: EAAccessoryDidConnectNotification object: nil];
[notificationCenter addObserver: self selector: @selector (accessoryDidDisconnect:) name: EAAccessoryDidDisconnectNotification object: nil];
NSArray *accessories = [accessoryMamaner connectedAccessories];
accessory = nil;
session = nil;
for (EAAccessory *obj in accessories)
{
if ([[obj protocolStrings] containsObject:@"com.XXXXX"] || [[obj protocolStrings] containsObject:@"com.YYYYYY"] )
{
accessory = obj;
break;
}
}
if (accessory)
{
session = [[EASession alloc] initWithAccessory:accessory forProtocol:@"com.dailysystems.DS247"];
if (!session) session = [[EASession alloc] initWithAccessory:accessory forProtocol:@"com.usaepay.ipos"];
if (session)
{
self.deviceConnected = YES;
[[session inputStream] setDelegate:self];
[[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[session inputStream] open];
[[session outputStream] setDelegate:self];
[[session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[session outputStream] open];
}
else
{
UIAlertView *accessoryInfo = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Hardware is not connected." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[accessoryInfo show]; [accessoryInfo release];
}
}
}
return self;
}
When i disconnect the accessory it gives me accessoryDidDisconnect and when i connect it gives me accessoryDidConnect,
But Problem is after that accessory stop working it does not respond to command. i tried to release the alloc and alloc again but no use.
Please tell me if some one have any idea how to get the accessory work again.
Thanks in advance.