DJISDKManager.bluetoothProductConnector returns nil
已完成Hi, I'm trying to add the DJI Mobile SDK (v4.16.2, iOS) in an app I'm building, but I'm running into a problem with one of the built-in APIs. In my application, I found that `DJISDKManager.bluetoothProductConnector()` always returns `nil`, so I cannot start connecting to my Osmo Mobile 2 gimbal.
I downloaded the sample code to check if I had an issue on my side, and while the Swift example indeed works correctly, the Objective-C example has the exact same issue I'm facing:
This leads me to wonder what the cause behind this is. Am I doing something wrong, which is also missing from the Objective-C example? What is the Swift example doing right?
I appreciate any insight people can give me that would help me to track down and eliminate the incorrect behaviour.
Thanks,
Alex
-
Hey, thanks for getting back. I was able to solve the issue on my end, and it appears it was a timing problem. Here's what I did at first, what didn't work:
- Invoked DJISDKManager.registerApp(with: self)
- In the callback (appRegisteredWithError(_:)), I immediately called DJISDKManager.startConnectionToProduct() and tried to get the Bluetooth connector via DJISDKManager.bluetoothProductConnector()
- The product connector function returned nil in this case
I then tried to dispatch this to main and wait a second before trying to access the connector:
_ = DispatchQueue.main.async {
DJISDKManager.startConnectionToProduct()
}
DispatchQueue.main.asyncAfter(deadline: .now().advanced(by: .seconds(1))) {
NSLog("\(#function) error = \(error?.localizedDescription ?? "n/a"), hasSDKRegistered = \(DJISDKManager.hasSDKRegistered()), bluetoothProductConnector = \(String(describing: DJISDKManager.bluetoothProductConnector()))")
}
Turns out this works! So it's likely some sort of timing issue. I disassembled bluetoothProductConnector() and it is checking the registration state and a flag somewhere, so perhaps it's just that these things are only being set correctly on the next run loop iteration after the delegate method is invoked?
Either way, this now works reliably for me.
请先登录再写评论。
评论
3 条评论