Get DJIBatteryState and Location of the Aircraft on iOS
357 1 2022-9-7
Uploading and Loding Picture ...(0/1)
o(^-^)o
djiuser_WIpZkFJugOwS
lvl.1

Italy
Offline

Hello everybody,
i have this problem with SDK for iOS. I cannot access any information from the drone such as the battery (charge remaining) or the current location of the drone.

On Android I did it like this, but I can't find an equivalent on iOS.I tried this:
let drone: DJIAircraft =  DJISDKManager.product() as! DJIAircraft
but DJIAircraft  and DJIFlightController do bot have any of this information


BaseProduct product = MApplication.getProductInstance();
    if (product != null && product.isConnected()) {
        if (product instanceof Aircraft) {
            mFlightController = ((Aircraft) product).getFlightController();
            ((Aircraft) product).getBattery().setStateCallback(new BatteryState.Callback() {
                @Override
                public void onUpdate(BatteryState batteryState) {
                    batteryRemainingPercent = batteryState.getChargeRemainingInPercent();
                }
            });
        }
    }
    if (mFlightController != null) {
        mFlightController.setStateCallback(new FlightControllerState.Callback() {

            @Override
            public void onUpdate(FlightControllerState djiFlightControllerCurrentState) {
               lat = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();               lng = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();            }
        });
    }
}


2022-9-7
Use props
djiuser_WIpZkFJugOwS
lvl.1

Italy
Offline

Ok, found the solution. You have to implement a delegate like this:
        let drone: DJIAircraft =  DJISDKManager.product() as! DJIAircraft
        drone.flightController?.delegate = self
        drone.battery?.delegate = self




and add : DJIFlightControllerDelegate, DJIBatteryDelegate to you script and implement the function of this protocol/interface

    public func battery(_ battery: DJIBattery, didUpdate state: DJIBatteryState) {
//code
    }

    public func flightController(_ fc: DJIFlightController, didUpdate state: DJIFlightControllerState) {
        //code
    }

2022-9-7
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules