Adonit / LAMY-iPadOS-SDK

0 stars 0 forks source link

Enabling the SDK in my app only works if I enable it in the Example app first. Please Help!! #11

Closed vectorinkllc closed 2 weeks ago

vectorinkllc commented 1 month ago

This is a very strange issue I'm running into.

Calling this: [[LamyStylusManager sharedInstance] enable];

Allows this event to observer to communicate to my app the status of the Lamy hardware.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectionChange:)
                                                  name:LamyStylusManagerDidChangeConnectionStatus object:nil];

And it works, only if I first connect to the Example provided in the SDK download. If I reboot my iPad and run my app by itself, the LamyStylusManagerDidChangeConnectionStatus event never fires and the SDK never gets enabled.

Any ideas on what I might be missing? Is there more to enabling the SDK than just calling [[LamyStylusManager sharedInstance] enable];?

adonitDevel commented 4 weeks ago

Hi @vectorinkllc, Did you follow the wiki steps to integrate our SDK, and how did you connect the Lamy stylus?

vectorinkllc commented 4 weeks ago

Yes I followed the wiki steps. And my implementation does work, but only after I connect via the example App that came with the SDK and rebuild my app in xcode. Then when I press the button to connect the pen in my app, the LamyStylusManagerDidChangeConnectionStatus event gets fired and I'm able to use all of the pens features in my app. But I can only get this to work if I open the example app first, connect, and then re-build my app in xcode. If I dont connect with the example app first LamyStylusManagerDidChangeConnectionStatus never fires. This issue is very strange, I know I sound totally mad just saying this but I figured this explanation might help you recognize exactly what my issue it. I don't thinks its a code issue, because it works (When it works), something it stopping LamyStylusManagerDidChangeConnectionStatus from firing after I enable the SDK.

My code is pretty straight forward, I have delegate that calls the methods on this LamySDKWrapper and handles the UI stuff

Here's the LamySDKWrapper.m `// LamySDKWrapper.m

import "LamySDKWrapper.h"

@implementation LamySDKWrapper

@end `

vectorinkllc commented 4 weeks ago

Ok, after re-installing the SDK framework, now I can't get it to work at all (even after connecting to the example app). So that tells me that the times where it did connect were probably some freak accidents that only happened at random chance? When I first implemented the SDK it worked every single time I tested with no problem. Now it doesn't work at all, with the same code in place. The bare bones of the integration is simple:

Am I missing anything? This was working flawlessly before. So I guess the questions is, what would cause [[LamyStylusManager sharedInstance] enable]; to fail at enabling the SDK and thus firing LamyStylusManagerDidChangeConnectionStatus events?

vectorinkllc commented 4 weeks ago

Ok after taking everything apart and putting back together piece by piece I was able to confirm that somehow my app was indeed piggy backing on the bluetooth connection from the example app this whole time. I proved that by removing the Privacy - Bluetooth Always Usage Description from my info.plist. Doing so causes the app to crash if I try to enable the SDK because bluetooth isn't allowed. Then I connected the pen with the example app, then I opened my app again and it connected successfully even though bluetooth is not allowed.

So no matter if I call enable this way DispatchQueue.main.async { if let stylusManager = LamyStylusManager.sharedInstance() { stylusManager.enable() } } or this way [[LamyStylusManager sharedInstance] enable]; It doesn't work unless I connect in the example swift app first. I was trying to use my own custom UI this whole time so what I'm going to try next is integrating the ViewController that comes with UI Bundle and see if that makes a difference.

adonitDevel commented 4 weeks ago

Hi @vectorinkllc In your case, it may be caused by the Bluetooth reconnection mechanism.

Do your apps have a UI like the connect stylus in the example app?

when you call "startDiscoveryAndImmediatelyConnect" this function, you should tell the user to press the tip. and you should receive LamyStylusManagerDidChangeConnectionStatus event.

vectorinkllc commented 4 weeks ago

That did it! "startDiscoveryAndImmediatelyConnect" is all I needed. Thanks!