iampnelson/LineaPro-TiModule — Issue #2: IOS 5 problem
Author: DavePatton
Created: 2011-12-10 18:04:33+00:00
State: open

I got the module to work on IOS 5 by following your suggestions but there is a problem. Every time my device locks the module becomes unusable, i.e., when I hold the scanner button the scanner light will not come on and then it comes on at some random time later and shuts off itself.

I wrote a native app and have it working without this problem by doing the following at the times when the device is locking and unlocking. The magic code from my native app is as follows..

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
linea=[Linea sharedDevice];
[linea addDelegate:self];
[linea connect];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[linea removeDelegate:self];
[linea disconnect];
}

I added lock/unlock detection to my titanium app and did the same thing essentially with the following code..

function BarcodeReceived(e) {
tableview1.appendRow(Ti.UI.createTableViewRow({title:e.source, hasChild:false}));
}
linea.addEventListener('barcodeData', BarcodeReceived);

var paused = 'false';
Titanium.App.addEventListener('pause',function(e)
{
paused = true;
//label.text = "App has been paused";
linea.removeEventListener('barcodeData', BarcodeReceived);
});

Titanium.App.addEventListener('resume',function(e)
{
if (paused)
{
//label.text = "App has resumed";
linea.addEventListener('barcodeData', BarcodeReceived);
paused = 'false';
Titanium.UI.createAlertDialog({title: 'App Resumed'}).show();
}
else
{
//label.text = "App has resumed (w/o pause)";
paused = 'false';
Titanium.UI.createAlertDialog({title: 'App Resumed w/o pause'}).show();
}
});

This doesn't seem to work even though I added the following to my obj-c module so I get the sam load/unload behavior..

-(void)_listenerAdded:(NSString *)type count:(int)count
{
if (count == 1 && [type isEqualToString:@"barcodeData"])
{
// the first (of potentially many) listener is being added
// for event named 'my_event'
}
linea=[Linea sharedDevice];
[linea addDelegate:self];
[linea connect];
}

-(void)_listenerRemoved:(NSString *)type count:(int)count
{
if (count == 0 && [type isEqualToString:@"barcodeData"])
{
// the last listener called for event named 'my_event' has
// been removed, we can optionally clean up any resources
// since no body is listening at this point for that event
}
[linea removeDelegate:self];
[linea disconnect];
}

Has anyone experienced this issue?