DJISDKManager.bluetoothProductConnector returns nil

已完成

评论

3 条评论

  • DJI Developer Support
    I was able to replicate the same issue in Objective-C. To resolve this, could you please try registering the SDK (registerAppWithDelegate) first and then obtaining the bluetoothProductConnector? Let me know if you have any further questions or concerns.
    0
    评论操作 固定链接
  • Alexander Repty

    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:

    1. Invoked DJISDKManager.registerApp(with: self)
    2. In the callback (appRegisteredWithError(_:)), I immediately called DJISDKManager.startConnectionToProduct() and tried to get the Bluetooth connector via DJISDKManager.bluetoothProductConnector()

       

    3. 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.

    0
    评论操作 固定链接
  • DJI Developer Support
    I'm glad to hear that you have found a solution. If you encounter any further issues, feel free to ask us. Have a great day!
    0
    评论操作 固定链接

请先登录再写评论。