2017-02-01 10 views
0

내 자신의 응용 프로그램을 특정 무인 장치에 연결할 수 없습니다. 브리 저 앱을 다운로드하고 디버깅에 사용하고 있습니다. 샘플 애플리케이션에서 "DJIBaseViewController"를 복사하여 내 자신의보기 컨트롤러에 위임자로 만들었습니다. 코드에 중단 점을 많이 추가 한 후 내 응용 프로그램과 샘플 응용 프로그램의 주요 차이점은 위임 메서드 "sdkManagerProductDidChange"입니다.DJI 무인 장치가 연결되지 않았습니다 (sdkManagerProductDidChange 대리자 메서드가 호출되지 않음)

// DJIBaseViewController.swift 


import UIKit 
import DJISDK 

protocol DJIProductObjectProtocol { 
    func fetchAircraft() -> DJIAircraft? 
    func fetchCamera() -> DJICamera? 
    func fetchGimbal() -> DJIGimbal? 
    func fetchFlightController() -> DJIFlightController? 
    func fetchRemoteController() -> DJIRemoteController? 
    func fetchBattery() -> DJIBattery? 
    func fetchAirLink() -> DJIAirLink? 
    func fetchHandheldController() -> DJIHandheldController? 
} 

class ConnectedProductManager: DJIProductObjectProtocol { 
    static let sharedInstance = ConnectedProductManager() 

    var connectedProduct:DJIBaseProduct? = nil 

    func fetchAircraft() -> DJIAircraft? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft) 
     } 
     return nil 
    } 

    func fetchCamera() -> DJICamera? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft).camera 
     } 
     else if (self.connectedProduct is DJIHandheld) { 
      return (self.connectedProduct as! DJIHandheld).camera 
     } 

     return nil 
    } 

    func fetchGimbal() -> DJIGimbal? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft).gimbal 
     } 
     else if (self.connectedProduct is DJIHandheld) { 
      return (self.connectedProduct as! DJIHandheld).gimbal 
     } 

     return nil 
    } 

    func fetchFlightController() -> DJIFlightController? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft).flightController 
     } 
     return nil 
    } 

    func fetchRemoteController() -> DJIRemoteController? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft).remoteController 
     } 
     return nil 
    } 

    func fetchBattery() -> DJIBattery? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft).battery 
     } 
     else if (self.connectedProduct is DJIHandheld) { 
      return (self.connectedProduct as! DJIHandheld).battery 
     } 

     return nil 
    } 

    func fetchAirLink() -> DJIAirLink? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIAircraft) { 
      return (self.connectedProduct as! DJIAircraft).airLink 
     } 
     else if (self.connectedProduct is DJIHandheld) { 
      return (self.connectedProduct as! DJIHandheld).airLink 
     } 

     return nil 
    } 

    func fetchHandheldController() -> DJIHandheldController? { 
     if (self.connectedProduct == nil) { 
      return nil 
     } 
     if (self.connectedProduct is DJIHandheld) { 
      return (self.connectedProduct as! DJIHandheld).handheldController 
     } 
     return nil 
    } 

    func setDelegate(delegate:DJIBaseProductDelegate?) { 
     self.connectedProduct?.delegate = delegate 
    } 

} 

class DJIBaseViewController: UIViewController, DJIBaseProductDelegate, DJIProductObjectProtocol { 

    //var connectedProduct:DJIBaseProduct?=nil 
    var moduleTitle:String?=nil 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     if (moduleTitle != nil) { 
      self.title = moduleTitle 
     } 

     // Do any additional setup after loading the view. 
    } 


    override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated) 

     if (ConnectedProductManager.sharedInstance.connectedProduct != nil) { 
      ConnectedProductManager.sharedInstance.setDelegate(self) 
     } 
    } 

    override func viewWillDisappear(
     animated: Bool) { 
     super.viewWillDisappear(animated) 
     if (ConnectedProductManager.sharedInstance.connectedProduct != nil && 
      ConnectedProductManager.sharedInstance.connectedProduct?.delegate === self) { 
      ConnectedProductManager.sharedInstance.setDelegate(nil) 
     } 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func product(product: DJIBaseProduct, connectivityChanged isConnected: Bool) { 
     if isConnected { 
      NSLog("\(product.model) connected. ") 
      ConnectedProductManager.sharedInstance.connectedProduct = product 
      ConnectedProductManager.sharedInstance.setDelegate(self) 

     } 
     else { 
      NSLog("Product disconnected. ") 
      ConnectedProductManager.sharedInstance.connectedProduct = nil 
     } 
    } 

    func componentWithKey(withKey key: String, changedFrom oldComponent: DJIBaseComponent?, to newComponent: DJIBaseComponent?) { 
     //  (newComponent as? DJICamera)?.delegate = self 
     if ((newComponent is DJICamera) == true && (self is DJICameraDelegate) == true) { 
      (newComponent as! DJICamera).delegate = self as? DJICameraDelegate 

     } 
     if ((newComponent is DJICamera) == true && (self is DJIPlaybackDelegate) == true) { 
      (newComponent as! DJICamera).playbackManager?.delegate = self as? DJIPlaybackDelegate 
     } 

     if ((newComponent is DJIFlightController) == true && (self is DJIFlightControllerDelegate) == true) { 
      (newComponent as! DJIFlightController).delegate = self as? DJIFlightControllerDelegate 
     } 

     if ((newComponent is DJIBattery) == true && (self is DJIBatteryDelegate) == true) { 
      (newComponent as! DJIBattery).delegate = self as? DJIBatteryDelegate 
     } 

     if ((newComponent is DJIGimbal) == true && (self is DJIGimbalDelegate) == true) { 
      (newComponent as! DJIGimbal).delegate = self as? DJIGimbalDelegate 
     } 

     if ((newComponent is DJIRemoteController) == true && (self is DJIRemoteControllerDelegate) == true) { 
      (newComponent as! DJIRemoteController).delegate = self as? DJIRemoteControllerDelegate 
     } 

    } 


    func showAlertResult(info:String) { 
     // create the alert 
     var message:String? = info 

     if info.hasSuffix(":nil") { 
      message = info.stringByReplacingOccurrencesOfString(":nil", withString: " success") 
     } 

     let alert = UIAlertController(title: "Message", message: "\(message ?? "")", preferredStyle: .Alert) 
     // add an action (button) 
     alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) 
     // show the alert 
     self.presentViewController(alert, animated: true, completion: nil) 
    } 


    func fetchAircraft() -> DJIAircraft?{ 
     return ConnectedProductManager.sharedInstance.fetchAircraft() 
    } 

    func fetchCamera() -> DJICamera? { 
     return ConnectedProductManager.sharedInstance.fetchCamera() 
    } 

    func fetchGimbal() -> DJIGimbal? { 
     return ConnectedProductManager.sharedInstance.fetchGimbal() 
    } 

    func fetchFlightController() -> DJIFlightController? { 
     return ConnectedProductManager.sharedInstance.fetchFlightController() 
    } 

    func fetchRemoteController() -> DJIRemoteController? { 
     return ConnectedProductManager.sharedInstance.fetchRemoteController() 
    } 

    func fetchBattery() -> DJIBattery? { 
     return ConnectedProductManager.sharedInstance.fetchBattery() 
    } 
    func fetchAirLink() -> DJIAirLink? { 
     return ConnectedProductManager.sharedInstance.fetchAirLink() 
    } 
    func fetchHandheldController() -> DJIHandheldController?{ 
     return ConnectedProductManager.sharedInstance.fetchHandheldController() 
    } 
} 

스플래시 화면을로드 한 후로드되는 첫 번째보기는 다음과 같습니다.

// MenuViewController.swift 
import UIKit 
import DJISDK 

let enterDebugMode=true 

class MenuViewController: DJIBaseViewController { 

    @IBOutlet weak var aircraft: UILabel! 
    @IBOutlet weak var productID: UILabel! 
       // Do any additional setup after loading the view. 
    @IBOutlet weak var appConectivity: UILabel! 


     var connectedProduct:DJIBaseProduct?=nil 
     var componentDictionary = Dictionary<String, Array<DJIBaseComponent>>() 

     let APP_KEY = "*******"//Please enter App Key Here 
     override func viewDidLoad() { 

      super.viewDidLoad() 
      let air = self.fetchAircraft() 

      if air == nil{ 
       aircraft.text?="no aircraft connected" 
      } 
      print(air?.model) 
      initUI(); 

      guard !APP_KEY.isEmpty else { 
       showAlert("Please enter your app key.") 
       return 
      } 
      DJISDKManager.registerApp(APP_KEY, withDelegate: self) 


      if DJISDKManager.product() == nil{ 
       productID.text?="Drone Not Connected" 
      } 
      else{ 
       productID.text? = "Drone Connected" 
      } 
     } 

     func initUI() { 
      self.title = "DJI iOS SDK Sample" 
      //sdkVersionLabel.text = "DJI SDK Version: \(DJISDKManager.getSDKVersion())" 
      //openComponents.isEnabled = false; 
      //bluetoothConnectorButton.isEnabled = true; 
      //productModel.isHidden = true 
      //productFirmwarePackageVersion.isHidden = true 
      //debugModeLabel.isHidden = !enterDebugMode 
     } 
    func showAlert(msg: String?) { 
     // create the alert 
     let alert = UIAlertController(title: "", message: msg, preferredStyle: .Alert) 
     // add the actions (buttons) 
     alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) 
     // show the alert 
     self.presentViewController(alert, animated: true, completion: nil) 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 



    /* 
    // MARK: - Navigation 

    // In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     // Get the new view controller using segue.destinationViewController. 
     // Pass the selected object to the new view controller. 
    } 
    */ 
} 
extension MenuViewController: DJISDKManagerDelegate{ 

     func sdkManagerDidRegisterAppWithError(error: NSError?) { 

      guard error == nil else { 
       self.showAlertResult("Error:\(error!.localizedDescription)") 
       appConectivity.text?="app isn't registering properly" 
       return 
      } 

      //Debug("Registered!") 

      if enterDebugMode { 

       DJISDKManager.enterDebugModeWithDebugId("10.202.38.238") 
       print("WTF") 
      }else{ 
       //DJISDKManager.enterDebugModeWithDebugId("10.202.38.238") 
       DJISDKManager.startConnectionToProduct() 
      } 

     } 

     func sdkManagerProductDidChange(From oldProduct: DJIBaseProduct?, To newProduct: DJIBaseProduct?) { 

      print("entered changed product") 
      if oldProduct==nil{ 
       print("old product is nill") 
      } 
      if newProduct==nil{ 
       print("new product is nill") 
      } 

      guard let newProduct = newProduct else 
      { 
       appConectivity.text? = "Status: No Product Connected" 

       ConnectedProductManager.sharedInstance.connectedProduct = nil 
       //logDebug("Product Disconnected") 
       return 
      } 

      //Updates the product's model 
      productID.text = "Model: \((newProduct.model)!)" 
      productID.hidden = false 

      if let oldProduct = oldProduct { 
       print("Product changed from: \(oldProduct.model) to \((newProduct.model)!)") 
      } 
      //Updates the product's firmware version - COMING SOON 

      //Updates the product's connection status 
      //appConectivity.text = "Status: Product Connected" 

      ConnectedProductManager.sharedInstance.connectedProduct = newProduct 
      productID.text?="product connected" 
      //openComponents.isEnabled = true; 
      //openComponents.alpha = 1.0; 
      //logDebug("Product Connected") 

     } 
    override func product(product: DJIBaseProduct, connectivityChanged isConnected: Bool) { 

      if isConnected { 
       print("Status: Product Connected") 
       //appConectivity.text?="Drone Recognized" 
      } else { 
       print("Status: No Product Connected") 
       //appConectivity.text="Atleast Its trying" 
      } 
     } 


    } 

sdkManager가 지정된 앱 키 및 bundler 식별자로 올바르게 등록 중입니다. 또한 com.dji.video, com.dji.protocol 및 com.dji.common의 세 가지 요소로 info.plist 파일에 "지원되는 외부 액세서리 프로토콜"을 추가했습니다.

여기에 꽤 오래 머물러있어 지긋 지긋했습니다. 누군가가 도움을 요청하기를 바랍니다.

미리 감사드립니다.

답변

0

나는 그것을 알아 냈다. 여기에서 문제는 샘플 응용 프로그램은 자사의 대표라는 것을입니다 DJISDK 그 같은 큰 만든 것을

func sdkManagerProductDidChangeFrom(oldProduct: DJIBaseProduct?, to newProduct: DJIBaseProduct?) 

조금 짜증나는 나의 대표가 작동 알고있는 반면 내 샘플 응용 프로그램에서 어떤 이유

func sdkManagerProductDidChange(from oldProduct: DJIBaseProduct?, to newProduct: DJIBaseProduct?) 

차이가 있지만 그것은 내가 추측하는 코드를 복사 할 때 얻는 것이다. 희망이 도로 아래 다른 사람에게 도움이 되길 ...

건배

P.S. 그들은 내가 그것을 사용할 수있는 함수의 목록을 밖으로 침을 내 확장 섹션 Xcode에 func를 입력했을 때 그것을 발견 할 수있는 방식으로 다시 변경할 수 있습니다 sdkManagerDidChange 그들 중 하나가 다른 입력 변수와 함께했다.

편집 : 누군가가 샘플 앱에서 작동하는 이유를 설명 할 수 있고 내 것이 아니라면 너무 멋질 것입니다.