0

I am working on a project with the Linea Pro Hardware Barcode scanner. For getting started I used the following answer How do I use the Linea-Pro SDK for IOS?

My App consists of a Navigation Controller (table with two entries) and two connected view controllers (each of them uses the scanner).

I am connecting the device in the viewDidLoad of the navigation controller like this:

dtdev=[DTDevices sharedDevice];
[dtdev connect];

In the two view controllers I am registering the device in the viewDidLoad method like this:

dtdev=[DTDevices sharedDevice];
[dtdev addDelegate:self];
[super viewDidLoad];

Unfortunately when I click the device scanning button both delegate methods of the two view controllers are invoked since both where registered for it.

To prevent this behavior I wanted to set the viewController as delegate as soon as the view is visible so I put the [dtdev addDelegate:self]; into the viewWillAppear method and put a [dtdev removeDelegate:self]; in the viewWillDisappear method. After that the bar code scanner will not work anymore after invoking removeDelegate, even if it is added via addDelegate again.

I don't see another way of just adding both view controllers as delegate and then puttin code like this in the delegate methods: "Am I visible"? --> continue : else break; (But this is stupid, right?)

Is it a bug or am I not thinking straight?

Community
  • 1
  • 1
cloudnaut
  • 982
  • 3
  • 13
  • 35

2 Answers2

0

I'm surprised the add/remove delegate doesn't work, sounds like a bug. If you have an example with a navigation controller that does only that, i'd suggest sending it to LineaPro.

Are you sure the sharedDevice is still set and that your dtdev isn't nil when you call addDelegate again?

The easy solution is probably just what you thought. Add this to the top of both delegates (since you are using a navigation controller).

if (self != self.navigationController.visibleViewController) return;

0

I had the same problem and I solved the problem by adding another:

[dtdev addDelegate:self];

in viewDidAppear method.

I hope this will help you.

hgwhittle
  • 9,316
  • 6
  • 48
  • 60