Connecting to Drone


The Core class in the SDK provides all the different methods required to discover and connect to the drone.  Before using the APIs in the SDK, make sure to follow the steps explained below in 'First steps to use framework'.

First steps to use framework

The steps below assume that your iOS device has a network connection to the drone, e.g. using WiFi. One way to start is to add a CoreManager to your iOS application:

import Foundation
import Dronecode_SDK_Swift
import RxSwift

class CoreManager {

    static let shared = CoreManager()

    let disposeBag = DisposeBag()

    let core = Core()
    let telemetry = Telemetry(address: "localhost", port: 50051)
    let action = Action(address: "localhost", port: 50051)
    let mission = Mission(address: "localhost", port: 50051)
    let camera = Camera(address: "localhost", port: 50051)

    private init() {}

    lazy var startCompletable = createStartCompletable()

    private func createStartCompletable() -> Observable {
        let startCompletable = core.connect().asObservable().replay(1)
        startCompletable.connect().disposed(by: disposeBag)

        return startCompletable.asObservable()

Connect to the Drone

Once you have added the CoreManager, use it in your view controller to listen to the connection status as shown below.

let coreStatus: Observable = CoreManager.shared().core.discoverObservable
        coreStatus.subscribe(onNext: { uuid in
                //get the UUID of the discovered drone
            }, onError: { error in
            .disposed(by: disposeBag)

You can also listen to connection timeout updates using the code snippet below.

let coreTimeout: Observable = CoreManager.shared().core.timeoutObservable
        coreTimeout.subscribe({Void in
                //connection timeout
            .disposed(by: disposeBag)