我正在使用DJI Mobile SDK和UXSDK示例应用程序(在这里找到:https://github.com/dji-sdk/Mobile-UXSDK-iOS)在swift中编写iOS项目 .
我添加了一个带有IBAction getData(_ sender :)的ViewController,它成功地向DJI产品发送消息 . 当IBAction完成时,应用程序崩溃并在AppDelegate.swift中出现EXC_BAD_ACCESS错误
AppDelegate中的错误标志
import UIKit
import Foundation
//To use DJI Bridge app, change `useBridge` to true and add bridge app
IP address in `debugID`
let useBridge = false
let debugIP = "BRIDGE_APP_IP_ADDRESS_HERE"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,
UISplitViewControllerDelegate {
var window: UIWindow?
open var productCommunicationManager = ProductCommunicationManager()
open var communicationsViewController = CommunicationsViewController()
open var osdkDevice:OnboardSDKDevice?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Start the registration at the launch of the app. This can be retriggered at anytime from the main view.
// DJI App key needs to be registered in the Info.plist before calling this method.
self.productCommunicationManager.registerWithProduct()
return true
}
}
这是视图控制器 . 它不是主要的,但它通过主视图控制器导航 .
import UIKit
import Foundation
import DJISDK
import DJIUXSDK
class CommunicationsViewController: UIViewController, UITextViewDelegate {
//This is instantiated as a UIViewController as soon as app launches
//The reference in appDelegate is reassigned every time the view launches
//MARK: Properties
@IBOutlet weak var DataDisplay: UITextView!
open weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
//MARK: Methods
override func viewDidLoad() {
super.viewDidLoad()
appDelegate?.communicationsViewController = self
appDelegate?.productCommunicationManager.connectToProduct()
appDelegate?.productCommunicationManager.connectedProduct = DJISDKManager.product()
if (appDelegate?.productCommunicationManager.connectedProduct?.model != nil){
self.DataDisplay.text = (appDelegate?.productCommunicationManager.connectedProduct.model)
}
appDelegate?.osdkDevice = OnboardSDKDevice()
appDelegate?.osdkDevice?.delegate = appDelegate?.osdkDevice
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//MARK: Actions
@IBAction func back(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
@IBAction func getData(_ sender: UIButton) {
//Create 4 bytes of 0's
let data = Data(count: 4)
appDelegate?.osdkDevice?.sendDataFromMobile(toOnboard: data, withCompletion: nil)
//App crashes after exiting scope
}
}
我发现EXC_BAD_ACCESS是由尝试访问不再可用的内存引起的 . 我仔细检查了所有IBActions和IBOutlets的连接,它们似乎没问题 .
这是来自控制台
的"bt"的错误消息
异常断点的控制台和程序集
有人可以帮我诊断崩溃吗? iOS编程和Swift对我来说都是新手,所以如果这个描述中有任何遗漏,请告诉我 . 谢谢