NativeScript / mlkit

Apache License 2.0
24 stars 9 forks source link

IOS Bug: onDetection methods not called on IOS, this is still issue #10 #19

Closed cjohn001 closed 2 years ago

cjohn001 commented 2 years ago

Please see issue https://github.com/NativeScript/mlkit/issues/10 . It is not solved yet. The context which is bound to the callback function is still wrong. Please look into referenced issue for screenshots of the debugger.

I see two problems in line:

https://github.com/NativeScript/mlkit/blob/353ede150655e33b36fb020be320653240dad285/packages/mlkit-core/index.ios.ts#L209

I assume the context of the callback function is TNSMLKitHelper instead of MLKitView. Therefore the first condition of the if statement fails.

This could be resolved by binding the callback to the MLKitView explicitly. Hence replace

https://github.com/NativeScript/mlkit/blob/353ede150655e33b36fb020be320653240dad285/packages/mlkit-core/index.ios.ts#L45

with

this.#mlkitHelper.onScanCallback = this._onScanCallback.bind(this);

However, then the second problem arises with the second condition in the if statement

this.hasListeners?

is unfortunately null. I unfortunately do not understand the logic behind this piece of code and therefore have no idea how to resolve the second part of the problem.

triniwiz commented 2 years ago

hasListeners was checking if there is an event registered but I might as well remove that check